git 错误:无法使用 rebase 拉取:您有未暂存的更改
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23517464/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Error: Cannot pull with rebase: You have unstaged changes
提问by user3597950
I have started collaborating with a few friends on a project & they use the heroku git repository.
我已经开始与几个朋友在一个项目上合作,他们使用 heroku git 存储库。
I cloned the repository a few days ago and they have since made some changes so I am trying to get the latest updates
几天前我克隆了存储库,此后他们进行了一些更改,因此我正在尝试获取最新更新
I ran the git pull --rebase
command as stated here(Is this the right way to do it?): https://devcenter.heroku.com/articles/sharing#merging-code-changes
我git pull --rebase
按照这里的说明运行了命令(这是正确的方法吗?):https: //devcenter.heroku.com/articles/sharing#merging-code-changes
I get the following error:
我收到以下错误:
$ git pull --rebase
Cannot pull with rebase: You have unstaged changes.
Please commit or stash them.
My guess is that I messed around with the code and now it wants me to either commit or discard(is that what does stash means?) the changes. Is this what is happening? If this is the case I would like to discard any changes I might have made and just get the updated code from the git repository.
我的猜测是我弄乱了代码,现在它要我提交或丢弃(这是 stash 意味着什么?)更改。这是正在发生的事情吗?如果是这种情况,我想放弃我可能所做的任何更改,只从 git 存储库中获取更新的代码。
Any idea of what I can do?
知道我能做什么吗?
回答by Schleis
Do git status
, this will show you what files have changed. Since you stated that you don't want to keep the changes you can do git checkout -- <file name>
or git reset --hard
to get rid of the changes.
做git status
,这将显示哪些文件已更改。既然你说你不想保留你可以做的更改git checkout -- <file name>
或git reset --hard
摆脱这些更改。
For the most part, git will tell you what to do about changes. For example, your error message said to git stash
your changes. This would be if you wanted to keep them. After pulling, you would then do git stash pop
and your changes would be reapplied.
大多数情况下,git 会告诉您如何处理更改。例如,您的错误消息表示git stash
您的更改。如果你想保留它们,这将是。拉动后,您将执行此操作git stash pop
并且您的更改将被重新应用。
git status
also has how to get rid of changes depending on if the file is staged for commit or not.
git status
还有如何根据文件是否暂存以进行提交来摆脱更改。
回答by mkobit
If you want to keep your working changes while performing a rebase, you can use --autostash
. From the documentation:
如果您想在执行变基时保留您的工作更改,您可以使用--autostash
. 从文档:
Before starting rebase, stash local modifications away (see git-stash[1]) if needed, and apply the stash when done.
在开始 rebase 之前,如果需要,将本地修改藏起来(请参阅git-stash[1]),并在完成后应用藏匿处。
For example:
例如:
git pull --rebase --autostash
回答by Kostas Rousis
Pulling with rebase is a good practice in general.
通常,使用 rebase 拉取是一种很好的做法。
However you cannot do that if your index is not clean, i.e. you have made changes that have not been committed.
但是,如果您的索引不干净,您就不能这样做,即您进行了尚未提交的更改。
You can do this to work around, assuming you want to keep your changes:
假设您想保留更改,您可以这样做来解决:
- stash your changes with:
git stash
- pull from master with rebase
- reapply the changes you stashed in (1) with:
git stash apply stash@{0}
or the simplergit stash pop
- 使用以下方法存储您的更改:
git stash
- 使用 rebase 从 master 拉取
- 重新应用您在(1)中隐藏的更改:
git stash apply stash@{0}
或更简单的git stash pop
回答by Igal S.
First start with a
git status
首先从一个
git status
See if you have any pending changes. To discard them, run
查看您是否有任何待处理的更改。要丢弃它们,请运行
git reset --hard
回答by CppChase
This works for me:
这对我有用:
git fetch
git rebase --autostash FETCH_HEAD
回答by Jared Updike
You can always do
你总能做到
git fetch && git merge --ff-only origin/master
and you will either get (a) no change if you have uncommitted changes that conflict with upstream changes or (b) the same effect as stash/pull/apply: a rebase to put you on the latest changes from HEAD and your uncommitted changes left as is.
如果您有与上游更改冲突的未提交更改或 (b) 与 stash/pull/apply 相同的效果,您将获得(a)没有更改照原样。
回答by tggagne
When the unstaged change is because git is attempting to fix eol conventions on a file (as is always my case), no amount of stashing or checking-out or resetting will make it go away.
当未暂存的更改是因为 git 试图修复文件上的 eol 约定时(就像我的情况一样),任何存储、检出或重置都不会使其消失。
However, if the intent is reallyto rebase and ignore unstaged changed, then what I do is delete the branch locally then check it out again.
但是,如果意图真的是变基并忽略未暂存的更改,那么我所做的就是在本地删除分支,然后再次检查它。
git checkout -f anyotherbranchthanthisone
git branch -D thebranchineedtorebase
git checkout thebranchineedtorebase
Voila! It hasn't failed me yet.
瞧!它还没有让我失望。
回答by agirault
If you want to automatically stash your changes and unstash them for every rebase, you can do this:
如果你想自动隐藏你的更改并为每个 rebase 取消隐藏它们,你可以这样做:
git config --global rebase.autoStash true