theArcticOcean

博观而约取,厚积而薄发

git add in different HEAD state

假设我们已经有这样的提交记录:

commit 86765d30e168e7501ce1d837b978bd89fa50c233 (HEAD -> master)
    :sparkles: update itoa.cpp

commit 519b6f810842d2ec67b0d0c84e401a30d4499574 (origin/master, origin/HEAD)
    :memo: update README.md

....

将commit id为86765d30e168e7501ce1d837b978bd89fa50c233的位置称之为A,将commit id为519b6f810842d2ec67b0d0c84e401a30d4499574的位置称之为B。现在想从A回到B,进行相关的修改,为该commit增加一个patch,然后回到A,做一些修改,为A增加一个patch。
回到B:

➜ CLib git:(master) git reset 519b6f810842d2ec67b0d0c84e401a30d4499574
Unstaged changes after reset:
M   itoa.cpp

接着,我们为该commit增加一个patch:

CLib git:(master)vim README.mdCLib git:(master)git add README.mdCLib git:(master)git commit --amend
[master e018045] :memo: update README.md
 Date: Sat May 26 15:34:23 2018 +0800
 1 file changed, 2 insertions(+), 1 deletion(-)

怎样回到A呢?
使用git reflog查看记录

e018045 (HEAD -> master) HEAD@{0}: commit (amend): :memo: update README.md
519b6f8 (origin/master, origin/HEAD) HEAD@{1}: reset: moving to 519b6f810842d2ec67b0d0c84e401a30d4499574
86765d3 HEAD@{2}: commit: :sparkles: update itoa.cpp

然后git reset回去

➜ CLib git:(master) ✗ git reset 86765d3
Unstaged changes after reset:
M   README.md
➜ CLib git:(master) ✗ git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

 modified: README.md

然后可以继续修改了

CLib git:(master)vim itoa.cppCLib git:(master)git add itoa.cppCLib git:(master)git commit --amend
[master c20582e] :sparkles: update itoa.cpp
 Date: Wed May 30 22:06:24 2018 +0800
 1 file changed, 2 insertions(+), 1 deletion(-)
阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/theArcticOcean/article/details/80518621
文章标签: git cvs
个人分类: linux
想对作者说点什么? 我来说一句

git 问题之解决

错误

wwq444968579 wwq444968579

2014-10-15 16:13:58

阅读数:7519

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭