git常用命令

1.git不区分大小文件的解决方法:

git mv -f mypoints.html myPoints.html

2.git提交代码:

  1>.git gui -> 缓存改动 ->提交描述 ->提交;

  2>.git add mypoints.html

     git add -A

       git commit -m 'update conflict'

  ps: 在代码冲突的时候,根据提示找到冲突的那个文件,解决完之后,按照第二种方法进行提交;第一种是普通的提交方式;

3.git更新代码:

  git fetch;git rebase;

  ps:在代码冲突的时候,这个时候rebase就失败了,按照2的第二种方式解决冲突之后,执行:git rebase --continue; 可以继续rebase;

4.git推送代码:

  git push;

5.git第一次下载代码:

  git clone git地址

6.git合并分支代码:

  git merge branchname

  ps:http://blog.csdn.net/hudashi/article/details/7668798

7.git设置推送时不区分文件名大小写问题:

  git config core.ignorecase false  

  或者git mv --force myfile MyFile

8.git推送本地分支到远程分支:

  git checkout local_branch

  git push origin local_branch:remote_branch

9.git merge后冲突合并:

  git mergetool --tool=vimdiff

9.1.还有一种冲突的解决方式:

  git fetch origin

  git merge origin/dev_branch

10.git推送tag

  

git tag -l
git push --tags
# 删除远程tag
git push origin :v1.1
# 删除远程tag
git push origin --delete tag V1.1
# 删除本地和远程tag
git tag -d V1.1
git push origin :V1.1
# 更新指定tag的代码(-b: 强制更新)
git checkout -b tag_name

  

 

11.撤销远程的某次提交:

  git log

  git revert 5962845b0059f9e7702b73066e6a35aea1efaa49

12.合并某一次提交:

  git cherry-pick 5106e0d415936c432f6ad21e80968c6535836ded

13.删除全局user.name,配置项目user.name:

  git config --global --unset user.name

  git config --global --unset user.email

  git config user.name 'your name'

  git config user.email 'your email'

14.冲突解决:

  git fetch origin

  git merge origin/your-branch

  git add -u
  git commit
  git push origin HEAD:refs/for/your-branch
15.撤销远程提交:
  http://learn.baidu.com/personalCenterLessonDetail.html?courseId=14551&state=3
16.完整的提交项目到远程仓库:
  
echo "# python-blog" >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/muzi131313/python-blog.git
git push -u origin master

  

17.git删除本地分支

# 同步与远程分支保持一致,简称
git fetch -p
# 更新本地分支与远程同步
git remote update origin --prune
# 删除远程分支
git push origin :bug-305-lyf

 

18.合并某次commit到另外一个分支:

# 切换到v2分支
git checkout v2
# 基于feature(v2)分支, 创建要一个最新的要提交的commit(不包含此commit)
git checkout -b newbranch 10940be3882c30f8efa56b04c808fb277d2b05f7
# rebase过来从哪个commit(不包含此commit)开始的commit
git rebase --onto master a7b6e4aff3e3c0b8de513cc86e7cdb21a51c8585
git checkout master
# 合并分支上的代码
git rebase newbranch
# 删除这个本地分支
git branch -D newbranch
# done: 合并v2分支上a7b6e4aff3e3c0b8de513cc86e7cdb21a51c8585的下一个 ~ 10940be3882c30f8efa56b04c808fb277d2b05f7区间的commit到mster

  

19. 创建本地分支,并关联远程分支

# 创建本地分支
git branch bug-crm-295
# 创建远程分支
git branch bug-crm-295:bug-crm-295
# 本地分支关联远程分支(第一次提交需要这样), 简写是 git push -u
git push --set-upstream origin bug-crm-295

 

20. 强制更新本地代码和远程保持一致

git set --hard origin/master

 

21. fatal: refusing to merge unrelated histories报错, 参考文章: https://blog.csdn.net/lindexi_gd/article/details/52554159   解决方法如下:

git pull --allow-unrelated-histories

22. git本地项目关联远程仓库:

# 初始化git
git init
# 仓库地址换成你远程的自己的仓库
git remote add origin git@gitee.com:muzi131313/repository.git

git add .
git commit -m 'init'
# 关联远程分支
git branch --set-upstream-to=origin/master master
# 两个不同的项目,要把两个不同的项目合并
git pull --allow-unrelated-histories
git pull
git push --set-upstream origin master
git push

  

23. git撤销本地commit和远程保持一致

 git reset –-hard origin/master 

14. git clone项目, 重新设置远程仓库地址

git remote set-url origin git@gitee.com:muzi131313/docker-examples.git

15.git生成sshkey

ssh-keygen -t rsa -C 'your-email@suffix.com'

 

posted @ 2016-03-16 11:54  muzi131313  阅读(257)  评论(1编辑  收藏  举报