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

本小妞迷上赌 提交于 2020-04-07 18:59:41

问题


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 status:

    # 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!


回答1:


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

Firstly, stash your changes

git stash

Then, pull in the changes from origin.

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

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

git stash pop



回答2:


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

  • 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.


来源:https://stackoverflow.com/questions/20568971/git-pull-keeps-telling-me-to-stash-local-changes-before-pulling

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