Reputation:
I create a project and init git with following infos
git config user.name 'name'
git config user.email '[email protected]'
and push the code to github, I use git log
, and find the email address is wrong, so i update it with following
git filter-branch --commit-filter '
if [ "$GIT_AUTHOR_EMAIL" = "[email protected]" ];
then
GIT_AUTHOR_EMAIL="[email protected]";
git commit-tree "$@";
else
git commit-tree "$@";
fi' -f HEAD
all commits are changed, and I push this to github again, but it fails with error
! [rejected] master -> master (non-fast-forward)
and ask me to pull, and i pull, but it show another error
* branch master -> FETCH_HEAD
fatal: refusing to merge unrelated histories
How can i fix this?
Upvotes: 0
Views: 952
Reputation: 3454
You rewrote the repository history with filter-branch. When you push to github it notices that your changes would overwrite the old history. To prevent you from losing history by accident, it refuses to do so.
Usually this happens when someone else pushes new changes before you. Pushing the history with your changes would overwrite their changes. So the error message suggests that you merge their changes and then push the combined histories.
From https://help.github.com/articles/dealing-with-non-fast-forward-errors/: git push origin master To https://github.com/USERNAME/REPOSITORY.git ! [rejected] master -> master (non-fast-forward) error: failed to push some refs to 'https://github.com/USERNAME/REPOSITORY.git' To prevent you from losing history, non-fast-forward updates were rejected Merge the remote changes (e.g. 'git pull') before pushing again. See the 'Note about fast-forwards' section of 'git push --help' for details.
However in your case the advice does not apply. You do not want to merge your rewritten history with your old history. You really want to lose the old history. In this case, you can tell Git using git push --force origin master.
Upvotes: 4
Reputation: 34722
You have rewritten your whole history with filter-branch
command, and that history is different from what you have in GitHub. You can forcibly push your local commits with git push -f
, it will override whatever you have in GitHub.
Upvotes: 1