Git:由于未提交的更改而无法变基

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21358872/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 17:38:14  来源:igfitidea点击:

Git: Cannot rebase because of uncommitted changes

gitgit-rebase

提问by Pixy

Git won't let me rebase from anywhere.

Git 不会让我从任何地方变基。

Cannot rebase: Your index contains uncommitted changes.
Please commit or stash them.

Following the instructions from this answer: https://stackoverflow.com/a/13694625/618450

按照此答案中的说明进行操作:https: //stackoverflow.com/a/13694625/618450

$ git update-index -q --ignore-submodules --refresh
$ git diff-files --ignore-submodules

Both do not produce any output but that one does:

两者都不会产生任何输出,但会产生:

$ git diff-index --cached --ignore-submodules HEAD --
:100644 000000 cab819f1e5ed6cc7cff374eecae273e1d6ae6a01     0000000000000000000000000000000000000000 D  .idea/codeStyleSettings.xml
:100644 000000 2953f353d2c65dd62e36926accb7f645a600b7e0 0000000000000000000000000000000000000000 D  .idea/dictionaries/roxy.xml
:100644 000000 0e7ecef362d8a77067edf4bae5972f33185bd986 0000000000000000000000000000000000000000 D  .idea/inspectionProfiles/Project_Default.xml
:100644 000000 3b312839bf2e939fea3ebdef15630a4b33e57caf  0000000000000000000000000000000000000000 D    .idea/inspectionProfiles/profiles_settings.xml
:100644 000000 e31af55b33d82e28f471a2ba51b63c2a91fa53b7 0000000000000000000000000000000000000000 D  .idea/php.xml
:100644 000000 9c25e8d4f1169b5d3103b14fdb60e7d7c3975b70 0000000000000000000000000000000000000000 D  db/sfront.sql

and I can't delete those files:

我无法删除这些文件:

$ git rm --cached .idea/php.xml
fatal: pathspec '.idea/php.xml' did not match any files

Any ideas that can help me?

任何可以帮助我的想法?

EDIT: git stash

编辑:git stash

Fixed my problem. I'm not sure I understand what happened though. The files that it complain about were supposed to be ignored.

解决了我的问题。我不确定我是否理解发生了什么。它抱怨的文件应该被忽略。

回答by jamesthollowell

git stashstores the different files away from everything else, returning your working directory to the last commit. Once you have done your rebase, run git stash pop. This will return those files to the working directory and allow you to work as before.

git stash将不同的文件与其他所有文件分开存储,将您的工作目录返回到最后一次提交。完成 rebase 后,运行git stash pop. 这会将这些文件返回到工作目录并允许您像以前一样工作。

EDIT: A good link for learning all about the git stashcommand: Git Tools - Stashing

编辑:学习所有git stash命令的好链接: Git Tools - Stashing

回答by Mike

Probably not yet for a golden shovel, nevertheless I always use --autostashoption when rebasing with uncommitted changes, thus:

可能还不是金铲子,但我总是在使用--autostash未提交的更改重新定位时使用选项,因此:

git rebase --interactive SHA_WHERE_REBASE_ONTO^ --autostash

git rebase --interactive SHA_WHERE_REBASE_ONTO^ --autostash