[英]How to amend last 2nd commit or specific commit only
In my current branch, I've 2 commits which are not pushed yet.在我当前的分支中,我有 2 个尚未推送的提交。
mainlineBranch:
commit 2 - recent commit
commit 1
I've few code changes & want to amend only to commit 1 without deleting commit 2. Can someone please help me?我的代码更改很少,只想修改提交 1 而不会删除提交 2。有人可以帮我吗?
git rebase --interactive
helps you. git rebase --interactive
可以帮助你。
First, stash your uncommitted changes for later use ( git stash
).首先,存储您未提交的更改以供以后使用(
git stash
)。 Your working directory should be clean now.您的工作目录现在应该是干净的。 Run
git rebase -i HEAD~3
and your editor will pop up with the following content:运行
git rebase -i HEAD~3
你的编辑器会弹出如下内容:
pick aaaaaaa
pick bbbbbbb
pick ccccccc
In the above example, bbbbbbb
should be your "commit 1" and ccccccc
should be your "commit 2".在上面的例子中,
bbbbbbb
应该是你的“commit 1”,而ccccccc
应该是你的“commit 2”。 Change pick
into edit
for bbbbbbb
and exit the editor.将选择更改为
pick
的edit
bbbbbbb
退出编辑器。 You can then git stash pop
the changes onto the working tree, which should be at commit 1 now.然后你可以
git stash pop
到工作树上,现在应该在提交 1 处。 Amend commit 1 with git commit --amend
and continue the rebase with git rebase --confinue
.使用
git commit --amend
修改提交 1 并使用git rebase --confinue
继续 rebase。 Assume conflicts are handled, you should now land on a new HEAD with a modified commit 1' and an identical commit 2'.假设已处理冲突,您现在应该使用修改过的提交 1' 和相同的提交 2' 登陆一个新的 HEAD。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.