我如何从我目前的状态转向在某个承诺上拍摄的截图?
如果我做 git 登录,那么我会得到以下输出:
$ git log
commit a867b4af366350be2e7c21b8de9cc6504678a61b`
Author: Me <me@me.com>
Date: Thu Nov 4 18:59:41 2010 -0400
blah blah blah...
commit 25eee4caef46ae64aa08e8ab3f988bc917ee1ce4
Author: Me <me@me.com>
Date: Thu Nov 4 05:13:39 2010 -0400
more blah blah blah...
commit 0766c053c0ea2035e90f504928f8df3c9363b8bd
Author: Me <me@me.com>
Date: Thu Nov 4 00:55:06 2010 -0400
And yet more blah blah...
commit 0d1d7fc32e5a947fbd92ee598033d85bfc445a50
Author: Me <me@me.com>
Date: Wed Nov 3 23:56:08 2010 -0400
Yep, more blah blah.
我如何转向11月3日的承诺,即承诺0d1d7fc?
但是,为了完整性,我也想展示这些其他替代解决方案,也可以用来逆转一个承诺(在这个意义上,你创建一个新的承诺,阻止了以前的承诺的变化,就像Git的逆转一样)。
替代方案1:硬和软重组
这是查尔斯·贝利(Charles Bailey)的解决方案的一个非常轻微修改的版本,以便在Git中通过SHA的Hash转向一个承诺吗?
# Reset the index to the desired commit
git reset --hard <commit>
# Move the branch pointer back to the previous HEAD
git reset --soft HEAD@{1}
# Commit the changes
git commit -m "Revert to <commit>"
这基本上是通过使用软重组将离开指数/重组区域的前承诺的状态,然后你可以承诺。
替代方案2:删除现有树,并用新树取代
git rm -r .
git checkout <commit> .
git commit
类似于替代 #1,这重复了当前工作副本中的 <commit> 状态. 首先需要做 git rm 因为 git checkout 不会删除自 <commit> 以来添加的文件。
但是,为了完整性,我也想展示这些其他替代解决方案,也可以用来逆转一个承诺(在这个意义上,你创建一个新的承诺,阻止了以前的承诺的变化,就像Git的逆转一样)。
替代方案1:硬和软重组
这是查尔斯·贝利(Charles Bailey)的解决方案的一个非常轻微修改的版本,以便在Git中通过SHA的Hash转向一个承诺吗?
# Reset the index to the desired commit
git reset --hard <commit>
# Move the branch pointer back to the previous HEAD
git reset --soft HEAD@{1}
# Commit the changes
git commit -m "Revert to <commit>"
这基本上是通过使用软重组将离开指数/重组区域的前承诺的状态,然后你可以承诺。
替代方案2:删除现有树,并用新树取代
git rm -r .
git checkout <commit> .
git commit
类似于替代 #1,这重复了当前工作副本中的 <commit> 状态. 首先需要做 git rm 因为 git checkout 不会删除自 <commit> 以来添加的文件。
但是,这里被问及如何取消具体的承诺,在这种情况下,它是取消过去的三个承诺,回到11月3日的承诺。
你可以用下调来做到这一点:
git rebase -i HEAD~4
这将列出你的最后四个承诺。
现在你有取消命令的选项,你用 drop 文本这样做。
只需在键盘上点击我,并在承诺旁边,您要删除写下滴,而不是默认选择在键盘上,点击输出和 :wq
要确保承诺被删除,写下:
git log
你會看到,當滴滴被移除時,你得救的行為。
要将这些变化推到您的远程分支,请写下:
git push --force