1

When we have committed local changes in a repo that have not been published, the right thing is to do a git pull --rebase to integrate them with upstream. This results in a clean, linear log. If we do a git pull, we get ugly merges, as git keeps our commits exactly the same in a kind of side branch, and automatically applies additional changes to integrate them. These merges are unnecessary, since the changes were never published and do not have to be preserved in the same form with the same SHA hashes. It's better if they are in a nice straight line of development with upstream.

Is there an easy way to undo to the effect of git pull and then re-do it with git pull --rebase?

Preventively, is there a way to get git pull to require an explicit --no-rebase or --rebase in order to proceed, when there are local commits, instead of assuming a default which may be wrong?

4

3 回答 3

2

您无需尝试重​​做,只需在键入git pull --rebase后再次键入git pull

于 2013-05-22T19:53:48.770 回答
1

看看git refloggit reset --hard拉之前的状态,git rebase --pull再看一遍。

您还可以设置为自动变基而不是合并新分支:

git config branch.autosetuprebase always

对于现有的分支

git config branch.*branch-name*.rebase true
于 2013-05-22T19:51:20.910 回答
0

在合并之前将 HEAD 和您的工作树回滚到上一个提交:

git reset --hard HEAD^
于 2013-05-22T19:51:34.207 回答