如何重置git author最近两次提交?

时间:2014-02-03 01:49:33

标签: git rebase

当我提交更改的文件时,如果btw远程和本地repo没有冲突,则在pull(或fetch)之后会自动再提交一次。

在这种情况下,如何在推送之前更改作者或电子邮件两次提交?

我知道如何更改内容,提交消息,作者,电子邮件......,最近的提交如下,

git commit --amend -m "hahaha"
git commit --amend --reset-author // reset author & author by configured

但是此命令修复了自动合并提交的内容。我不知道修复我所提交内容的方法。

PS。

我已经尝试了rebase -i(我承诺的id)。它显示如下。

pick (id which is the recent commit in remote server, not mine) "commit message....."

但我是git的初学者,我不知道具体的含义。

提前致谢。

1 个答案:

答案 0 :(得分:0)

如果您想在HEAD提交之前修改提交,则需要使用git rebase。在您的示例中,您在本地分支上进行了提交。在您的上游,自上次拉动以来,已经进行了几次新的提交。现在,当您拉动时,除了在上游进行的提交之外,您还将获得合并提交。因此,在拉动之后你会得到类似的东西:

* merge commit (HEAD)
|\
* | your commit
| * someone else's commit
|/
* common merge ancestor

从你的描述我认为你想修改上面的“你的提交”。在重新定位时,您总是希望在要更改的第一次提交之前开始提交。因此,要执行此操作,请执行以下操作:

git rebase -i HEAD~~

这意味着“在HEAD的第一个父级的第一个父级的第一个父级上启动一个rebase,在这种情况下,rebase将从中开始的提交是上面的”common merge ancestor“提交。您还可以指定标记,分支,提交哈希或解析为提交的任何其他引用,而不是HEAD~~

使用-i选项,rebase将生成一个编辑器(vim,nano等)来编辑提交。这是一些示例输出:

pick a7681b2 merge commit
pick 10b5421 your commit

# Rebase c9e3a52..10b5421 onto c9e3a52
#
# Commands:
#  p, pick = use commit
#  r, reword = use commit, but edit the commit message
#  e, edit = use commit, but stop for amending
#  s, squash = use commit, but meld into previous commit
#  f, fixup = like "squash", but discard this commit's log message
#  x, exec = run command (the rest of the line) using shell
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out

(如果您想使用与默认运行不同的编辑器,请将EDITOR环境变量设置为您喜欢的任何编辑器,例如在.bashrcexport EDITOR=vim

因此,为了修改“你的提交”,你只需用“编辑”代替“选择”:

pick a7681b2 merge commit
edit 10b5421 your commit

然后当您保存文件时,rebase将检出该提交并允许您运行所需的任何git commit amend命令。一旦您将提交编辑到您喜欢的运行git rebase --continue

最后一点,它似乎在这种性质的git pull上你希望创建一个合并提交。您可以通过执行git pull --rebase来解决此问题并获得更清晰的历史记录,这将自动在您的上游HEAD上重新提交您的提交。如果你这样做了,你的历史将会是这样的,而不是我在上面所说的:

* your commit
* someone else's commit
* common merge ancestor

在许多希望他们的git历史记录尽可能线性的商店中,必须执行git pull --rebase

相关问题