[英]How to redo squash some selected commits on branch
How to redo or undo squash some selected commits on a branch, in simple word my question is如何重做或撤消压缩分支上的某些选定提交,简而言之,我的问题是
commits is ABCDEFG
提交是 ABCDEFG
commits is AB-CD-EF-G
提交是 AB-CD-EF-G
commits is AB-CD-E-FG
Is there something I am wrong to let me correct.有什么我错了让我纠正。 I am just trying to simplify my query
我只是想简化我的查询
The action you did to go from 1.
to 2.
has rewritten your history, so G
in 2.
does not have the same hash as G
in 1.
您从
1.
到2.
对 go 所做的操作已经改写了您的历史记录,因此2.
中的G
与 1. 中的G
不具有相同的 hash 1.
Re-taking your notation:重新使用你的符号:
- first time
第一次
commits is ABCDEFG
提交是 ABCDEFG
- after squash some commits they are
在压缩了一些提交之后,它们是
commits is AB-C'-D'-EF-G'
提交是 AB-C'-D'-EF-G'
To undo the rewrite, you need to get the hash of your original G
commit (not G'
).要撤消重写,您需要获取原始
G
提交(不是G'
)的 hash 。
Your local git repo should still have it in its reflog:您本地的 git 存储库仍应在其 reflog 中包含它:
# in the following list of commits, spot the one that would match your initial commit :
git reflog
# you will have a shorter list if you look at the reflog of your working branch :
git reflog my/branch
Once you have that hash:一旦你有了 hash:
git reset --hard <that hash>
,git reset --hard <that hash>
, mandatory warning about git reset --hard
:关于
git reset --hard
的强制警告:
git reset --hard
is one of those few destructive git commands: if you have changes on your disk (on tracked files) that aren't stored in git, this command will forcefully drop these changes, and re-set the files content to the target commit's content. git reset --hard
是为数不多的破坏性 git 命令之一:如果您的磁盘(跟踪的文件)上有未存储在 git 中的更改,则此命令将强制删除这些更改,并重新设置这些文件的内容目标提交的内容。
This is why it is advised to look at your local changes first, and know for sure that the changes you discard are not important.这就是为什么建议首先查看您的本地更改,并确定您丢弃的更改并不重要。 The way to keep them is easy: just create a commit or a stash -- they will at least be reachable from the reflog afterwards.
保存它们的方法很简单:只需创建一个提交或存储——它们至少可以在之后从 reflog 中访问。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.