git日常使用经验积累

1 git merge origin/develop 将远程分支合并到本地,一般先执行合并,解决冲突,然后再git commit合入新建的分支,推送到远程分支里面,最后码云上找pl pull request到develop分支,对于有pull request还没审通过时,

 再次提交的代码不会再次创建pull request,会自动合并到之前的pull request里面,等一次审核通过就行。

 
2 已经commit到本地的代码,如果想放弃,可以回退使用git reset --hard 指定版本
 
3 冲突解决:
merge或者git pull后有代码冲突时,使用git mergetool命令解决冲突,然后再提交合入
 
4 提交代码
git commit -m "注释"
 
5 已经add到缓存区的代码,可以使用git rm --cache 文件名来释放到本地代码修改,如果修改的代码不想要了,然后就可以直接使用git checkout .
 
6 使用git commit前一定要先git pull一下,更新到最新代码,以免引起大规模冲突。
 
7在使用中遇到如下问题,可使用解决方案:

用git也是走了很多弯路。 
比如: 
这种错误 
1.

$ git commit -a
fatal: Unable to create 'E:/****/.git/index.lock': File exists.

Another git process seems to be running in this repository, e.g.
an editor opened by 'git commit'. Please make sure all processes
are terminated then try again. If it still fails, a git process
may have crashed in this repository earlier:
remove the file manually to continue.

解决方法: 
使用了$ rm -f ./.git/index.lock

然后我估计是点击了编辑,就出现了这个鬼

<****.github.io/.git/COMMIT_EDITMSG[+][RO] [unix] (18:21 22/07/2016)1,0-1 All
  • 1

输入:wq!(千万要记住!要加上去,万恶的电脑,少个符号都识别不了,这就是为什么我喜欢人脑) 
然后就正常了 
还有这种错误: 
2. 
这里写图片描述

出现这个问题是因为,没有在github账号添加SSH key, 
为了方便,我用了HTTPS协议

8 查看日志

git log --pretty=oneline

9 git diff HEAD -- readme.txt 查看本地和版本库里面的区别

10 git 删除远程分支git push origin -d BranchName

11 git branch --set-upstream-to=origin/o87   新创本地分支关联远程分支

11 

1    打开本地仓库位置,Git Bash here

2    把想要同步的这个仓库关联到本地 upstream 

执行:git remote add upstream https://github.com/*******.git     

3    查看状态确认是否配置成功

执行:remote -v         

4 拉取仓库下所有分支

执行: git fetch upstream 

5 把上游的远程代码合并到本地的 master分支

git checkout master

git merge upstream/master 
6 现在你的本地master就同步到最新版了。执行: git push 推到你的远程就好了

17 代码回退到某个节点

git reset --hard 版本号

git push origin 分支 --force强推到某个分支

posted on 2018-04-19 11:52  夏飞勇  阅读(191)  评论(0编辑  收藏  举报