切换导航
{{systemName}}
{{ info.Title }}
{{info.Title}}
{{ menu.Title }}
{{menu.Title}}
登录
|
退出
搜索
git团队管理工具使用及搭建
作者:ych
下载地址:[git官网](https://www.git-scm.com/download/ "git官网") 可以下载:[tortoisegit](https://tortoisegit.org/download/ "tortoisegit")(搭配图标和试图进行查看) 忽略文件样板:https://github.com/github/gitignore/ #### 基础知识 ``` git init //初始化本地git仓库 git add
//添加文件 git status //查看状态 git commit //提交 git push //推送到仓库 git pull //从远程仓库拉取数据 git clone //从远程仓库拷贝数据 ``` #### 进行提交最新代码 ``` git add . //后面有一个点,意思是将你本地所有修改了的文件添加到暂存区 git commit -m "" //引号里面是你的介绍,就是你的这次的提交是什么内容,便于你以后查看,这个是将索引的当前内容与描述更改的用户和日志消息一起存储在新的提交中 git commit -a -m "" //全部提交,直接一步到位 git pull origin 远程分支名 //从仓库下拉代码合并 git push origin master(git push origin 本地分支名:refs/remotes/远程分支名) //将代码推至远程就可以了 ``` #### 第一次初始化并获取和提交代码 Git global setup首先设置邮箱和用户名 ``` git config --global user.name "你的用户名" git config --global user.email "你的邮箱" ``` 拉取仓库 ``` cd existing_folder git init git remote add origin git地址 ``` 拉取项目 ``` git pull origin master ``` 文件复制到项目下面并提交新文件 ``` git add . git commit -m "Initial commit" git push -u origin master ``` 之后可以直接使用git push直接提交。 其中不设置全局用户名和邮箱还可以使用 ``` http://用户名:密码@地址 ``` #### 其他相关 ``` git init //初始化本地git仓库 git config --global user.email "923374829@qq.com" //已配置过可忽略 git config --global user.name "yincihang" //已配置过可忽略 git add index.html //添加index.html到仓库 git status //查看添加状态 git rm --cached index.html //移除git文件 git add *.html //添加html后缀的文件 touch .gitignore //添加忽略文件 git branch test20191219 //创建分支 git checkout test20191219 //切换分支 git merge test20191219 //合并分支到主分支 git remote //查看是否有远程地址 ``` #### 分支处理 1)创建本地分支mypc: ``` git checkout -b mypc ``` 2)推送创建远程分支mypc: ``` git push origin mypc ``` 3)检查分支: ``` git branch ``` 4)切换到主分支master: ``` git checkout master ``` 5)主分支下pull完成,合并mypc分支到主分支: ``` git merge mypc ``` 6)推送合并结果: ``` git push origin master ``` #### 问题处理 ##### 一直提示输入密码 可能你会一直提示输入密码,这个时候应该是凭证有问题,那么就修改凭证吧,控制面板->用户账号->管理您的凭证:将错误凭证删除并添加正确凭证的用户名密码等信息。 ##### 提示错误:fatal: remote origin already exists. 最后找到解决办法如下: 1、先删除远程 Git 仓库 ``` git remote rm origin ``` 2、再添加远程 Git 仓库 ``` git remote add origin ssh://web@www.jiyuwu.com:28/jiyuwu.git ``` 如果执行 git remote rm origin 报错的话,我们可以手动修改 gitconfig文件的内容 ``` vi .git/config ``` 把 `[remote “origin”]` 那一行删掉就好了。 ##### error: failed to push,hint: Updates were rejected because the tip of your current branch is behind 版本和本地版本冲突的解决方法,勾选强制覆盖已有的分支(可能会丢失改动),再点击上传,上传成功。 ``` git push -u origin master -f ``` ##### error: cannot lock ref 'refs/remotes/origin/xxx': unable to resolve reference refs/remotes/origin/xxx: Invalid argument ! [new branch] xxx -> origin/xxx(unable to update local ref) git bash here执行: ``` rm .git/refs/remotes/origin/xxx ``` ok,再试一遍问题解决。 ##### stderr: error: bad signature fatal: index file corrupt 1.输入 ``` rm -f .git/index ``` 出现 ssss@DESKTOP-ssssMINGW64 /e/project/ssss(master) 2. 再输入 ``` git reset ``` 出现提交过的文件,ok。 ##### git使用http方式提交代码不输入密码 ? 背景: 假如你创建项目地址为 http://git.ops.test.com.cn/root/puppet.git 。 解决: 如果你已经执行过 git clone http://git.ops.test.com.cn/root/puppet.git ,则可以进入puppet目录,修改 .git/config中url = http://账号:密码@git.ops.test.com.cn/root/puppet.git ,再提交就发现不要输入密码了;或者直接在克隆仓库的时候直接 git clone http://账号:密码@git.ops.test.com.cn/root/puppet.git ,这样下次提交时也不需要输入密码。 ##### 创建了一个origin,两个人分别clone 分别做完全不同的提交 第一个人git push成功 第二个人在执行git pull的时候,提示 fatal: refusing to merge unrelated histories 解决方法: ``` git pull origin master --allow-unrelated-histories ``` ##### stderr: error: bad signature fatal: index file corrupt 在项目有.git这同级打开Git Bash Here 1.输入 ``` rm -f .git/index ``` 出现 ssss@DESKTOP-ssssMINGW64 /e/project/ssss(master) 2. 再输入 ``` git reset ``` ok,解决。 ##### ! [rejected] master -> master (non-fast-forward) error: failed to push some refs to 'git@gitee.com:jiyuwu/TemplateCore.git' hint: Updates were rejected because the tip of your current branch is behind hint: its remote counterpart. Integrate the remote changes (e.g. hint: 'git pull ...') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details. 出现这个问题是因为远程分支上存在本地分支中不存在的提交,是多人开发中遇到的问题,可以先fetch 再merge,也就是pull,把运程分支上的提交合并到本地分支之后再push. ``` git push origin master -f //强行让本地分支覆盖远程分支 ``` `git pull` :命令用于从另一个存储库或本地分支获取并集成(整合).作用:取回远程主机某个分支的更新,再与本地的指定分支合并 使用语法: ``` git pull [options][
][
..] ``` $ git fetch:相当于是从远程获取最新版本到本地,不会自动合并。 如果还想要远程分支上的提交: git新版本的使用旧的pull命令:$ git pull origin master并不会解决问题,需要改为: ``` git pull origin master --allow-unrelated-histories ``` ##### 提交失败 ``` git pull origin 新建分支。 ```
相关推荐
git visual studio 无法提交kex_exchange_identification: Connection closed by remote host Connection closed
git推送
git创建/删除本地branch(分支),tag(标签)
github使用
git大小写改变提交
git查看本地ssh密钥
git代码合并
合并分支解决冲突
git回滚到某次提交
git合并分支
git
评论区
先去登录
版权所有:机遇屋在线 Copyright © 2021-2025 jiyuwu Co., Ltd.
鲁ICP备16042261号-1