git

1.版本回退

  • git reset HEAD^ 回退到上一版本,修改会放到工作区
  • git reset --soft HEAD^ 回退到上一版本,修改会放到暂存区
  • git reset --hard HEAD^ 回退到上一版本,修改就没了

  • git reset HEAD 暂存区的目录树会被重写,被 master 分支指向的目录树所替换,但是工作区不受影响

  • git checkout 从暂存区将文件恢复到工作区,如果工作区已经有该文件,则会选择覆盖

  • git checkout HEAD 会用 HEAD 指向的 master 分支中的全部或者部分文件替换暂存区和以及工作区中的文件

2.diff

  • git diff 查看工作区和暂存区的区别
  • git diff --cached 查看暂存区和版本库的区别
  • git diff HEAD 查看工作区和版本库的区别

  • git diff ce4366d 3930ce8 查看两个版本之间的区别
  • git diff master origin master

3.分支merge

  • git merge dev 合并dev分支到当前分支
    dev分支在当前分支的基础上又走了一步。则可以直接合并,fast forward
$ git log --graph --pretty=oneline --abbrev-commit
*   cf810e4 (HEAD -> master) conflict fixed
|\  
| * 14096d0 (feature1) AND simple
* | 5dc6824 & simple
|/  
* b17d20e branch test
* d46f35e (origin/master) remove test.txt
* b84166e add test.txt
* 519219b git tracks changes
* e43a48b understand how stage works
* 1094adb append GPL
* e475afc add distributed
* eaadf4e wrote a readme file

master分支和feature分支都又走了一步

$ git merge feature1
Auto-merging readme.txt
CONFLICT (content): Merge conflict in readme.txt
Automatic merge failed; fix conflicts and then commit the result.

$ git add readme.txt 
$ git commit -m "conflict fixed"
[master cf810e4] conflict fixed
  • no ff
$ git merge --no-ff -m "merge with no-ff" dev
Merge made by the 'recursive' strategy.
 readme.txt | 1 +
 1 file changed, 1 insertion(+)



$ git log --graph --pretty=oneline --abbrev-commit
*   e1e9c68 (HEAD -> master) merge with no-ff
|\  
| * f52c633 (dev) add merge
|/  
*   cf810e4 conflict fixed
...
  • git merge --squash issue1 将issue1的所有分支的提交合并成一个提交
  1. 回退merge,git revert HEAD
* a2adeb838fd1d3511ade411a39805747c2b60cda (HEAD -> master) Revert "fix bug"
* 0eb5a6161aee95280f7f26386c24c0fe5f3b174c fix bug
* ce4366dbff25d702bd5b059b31a2a375b69050c9 test 5

用一次新的提交去取消上次的提交

  1. 已有人推送到远程dev push冲突
  • git branch --set-upstream-to=origin/dev dev
  • git pull origin/dev
  • 合并冲突,手动解决,解决后提交,再push
  1. 版本号整合
  • 在最新的版本上修改
    git commit --amend
  • 合并已commit的版本号
    git rebase -i HEAD~~

7.分支

  • git checkout -b dev
  • git checkout -b dev origin/dev

  • git branch -a

  • git checkout master

  • git branch -d dev

8.远程仓库


  • git push -u origin master

  • git branch --set-upstream-to=origin/dev dev
  1. git stash
  • git stash
  • git stash list
  • git stash apply stash@{0}
  • git stash drop
  • git stash pop
  • git tag v0.9 fs2cb33

将merge拉直

  • git checkout feature
  • git rebase之后
  • git checkout master
  • git merge feature

12.将其他分支的commit倒入到本分支

  • git checkout master
    Switched to branch 'master'
  • git cherry-pick 99daed2
  • https://backlog.com/git-tutorial/cn/stepup/stepup7_4.html

你可能感兴趣的:(git)