Cannot pull with rebase

坚强是说给别人听的谎言 提交于 2019-12-09 15:43:23

问题


I get this message:

Cannot pull with rebase: You have unstaged changes.
Please commit or stash them.

Yes, I have changes which are not committed. I searched a way to rebase my uncommitted changes on top of the new code which I would get from a pull.

I found this: https://github.com/aanand/git-up

I want to know if this is still the way to go, or if there are more modern ways to go.

I use git version 1.8.1


回答1:


git-up is probably the more sophisticated way to solve this issue.
Otherwise, you need to stash, rebase and stash pop.

The "more modern way" will be available in git 1.8.5 (or 1.9, Q4 2013).
As I mention in "Git - How to edit old (not previous) commit with some of the unstaged changes from current index (current state)?":

"git rebase" learned "--[no-]autostash" option to save local changes instead of refusing to run (to which people's normal response was to stash them and re-run).


Since Git 2.9 (June 2016), you now have (as commented by artofwarfare):

git pull --rebase --autostash



回答2:


You can't really "rebase" your uncommitted changes since git does not know about them yet. You should stash your local changes before you run git pull --rebase then apply them back.




回答3:


You can use the Python port of git-up: https://github.com/msiemens/PyGitUp

pip install git-up



回答4:


I answer a little late but maybe that can be useful for someone.

If you are just looking for a one-liner to execute stash / pull rebase / stash pop, you can create an alias.

git config --global alias.spr '!f(){ git stash && git pull --rebase && git stash pop; };f'

This creates an alias named spr that does the three operations and allows you to quickly pull --rebase while you have unstaged changes.

git spr


来源:https://stackoverflow.com/questions/18852210/cannot-pull-with-rebase

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!