git pull:一直告诉我在拉取之前隐藏本地更改

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

git pull: keeps telling me to stash local changes before pulling

gitgit-mergegit-pull

提问by Jasper

When I am trying to pull my git repository with "git pull", it keeps telling me that I have local changes although I have not touched any of the mentioned files. Can someone explain this behavior and knows a solution?

当我尝试使用“git pull”拉我的 git 存储库时,它一直告诉我我有本地更改,尽管我没有触及任何提到的文件。有人可以解释这种行为并知道解决方案吗?

git status:

git状态:

    # On branch master
# Your branch is behind 'origin/master' by 1 commit, and can be fast-forwarded.
#   (use "git pull" to update your local branch)
#
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   modified:   src/component/Provider.java
#   modified:   src/data/Cascading.java
#
no changes added to commit (use "git add" and/or "git commit -a")

Solved the problem.It was actually my fault not noticing that the remote repository has been reset to a previous version. Nevertheless if you experience this, the solution explained by Max Woolf will work!

解决了问题。没有注意到远程存储库已重置为以前的版本,这实际上是我的错。尽管如此,如果您遇到这种情况,Max Woolf 解释的解决方案将起作用!

回答by Max Woolf

It sounds like your local branch does not have all of the changes on origin.

听起来您当地的分支机构没有对origin.

Firstly, stash your changes

首先,隐藏您的更改

git stash

Then, pull in the changes from origin.

然后,从 中拉入更改origin

git fetch origin && git rebase origin/(branch name)

Next, add the stash back in to your working directory:

接下来,将 stash 添加回您的工作目录:

git stash pop

回答by bredikhin

Git simply can't pull the changes if the files you have edited locally were changed on the remote. Basically, you have two choices:

如果您在本地编辑的文件在远程更改,则 Git 根本无法提取更改。基本上,您有两个选择:

  • stage and commit your changes, then Git will try to merge it during the pull (or ask for your help);
  • stash the changes, which puts them aside so you could pull the remote code and then re-apply your modifications.
  • 暂存并提交您的更改,然后 Git 将在拉取期间尝试合并它(或寻求您的帮助);
  • 隐藏更改,将它们放在一边,以便您可以提取远程代码,然后重新应用您的修改。