1

有一次,我不小心用错误的作者电子邮件将提交推送到远程存储库。我用了

git filter-branch -f --env-filter "GIT_AUTHOR_NAME='Niklas Rosenstein'; GIT_AUTHOR_EMAIL='<<email>>'; GIT_COMMITTER_NAME='Niklas Rosenstein'; GIT_COMMITTER_EMAIL='<<email>>';" HEAD

改写历史。然后我用

$ git push origin development
    Enter passphrase for key '----':
    To git@gitlab_cip:rosenstein/beak.git
     ! [rejected]        development -> development (non-fast-forward)
    error: failed to push some refs to 'git@gitlab_cip:rosenstein/beak.git'
    hint: Updates were rejected because the tip of your current branch is behind
    hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
    hint: before pushing again.
    hint: See the 'Note about fast-forwards' in 'git push --help' for details.

$ git pull origin development
    Enter passphrase for key '----':
    From gitlab_cip:rosenstein/beak
     * branch            development -> FETCH_HEAD
    Merge made by the 'recursive' strategy.

$ git push origin development
    Enter passphrase for key '----':
    Counting objects: 430, done.
    Delta compression using up to 2 threads.
    Compressing objects: 100% (336/336), done.
    Writing objects: 100% (402/402), 43.93 KiB | 0 bytes/s, done.
    Total 402 (delta 262), reused 85 (delta 65)
    To git@gitlab_cip:rosenstein/beak.git
       dd06969..2b2ddb4  development -> development

这可能是一个巨大的错误。

图形

我的所有提交都翻了一番!错误提交的作者已修复(很好地复制,然后更改),但原始提交也存在!

后来我读到我(可能)应该使用

git push origin --force development fix

我能以某种方式解决这个问题吗?

4

1 回答 1

1

如果最近没有人从您的远程仓库中提取,您可以:

git checkout development

# Make sure you don't have any work in progress
# That will cancel the merge (assuming you didn't make any new commits on it)
git reset --hard HEAD^1

# replace the development branch by your new history
git push origin --force development

(来自手册页的SPECIFYING REVISIONS部分)git rev-parse

我使用^1而不是~1为了选择第一个父级(在您的开发分支中),而不是第二个父级(来自起源/开发的那个,合并到您的分支中)。
话虽这么说,~1(第一个祖先)可能也会起作用。

于 2013-10-19T12:52:06.490 回答