Git Pull While Ignoring Local Changes?

前端 未结 12 1700
醉话见心
醉话见心 2020-12-04 04:29

Is there a way to do a git pull that ignores any local file changes without blowing the directory away and having to perform a git clone?

相关标签:
12条回答
  • 2020-12-04 04:52

    Look at git stash to put all of your local changes into a "stash file" and revert to the last commit. At that point, you can apply your stashed changes, or discard them.

    0 讨论(0)
  • 2020-12-04 04:52

    shortest way to do it is:

    git pull --rebase --autostash
    
    0 讨论(0)
  • 2020-12-04 04:53

    I usually do:

    git checkout .
    git pull
    

    In the project's root folder.

    0 讨论(0)
  • 2020-12-04 04:55
    git fetch --all && git reset --hard origin/master
    
    0 讨论(0)
  • 2020-12-04 04:57

    .gitignore

    "Adding unwanted files to .gitignore works as long as you have not initially committed them to any branch. "

    Also you can run:

    git update-index --assume-unchanged filename
    

    https://chamindac.blogspot.com/2017/07/ignoring-visual-studio-2017-created.html

    0 讨论(0)
  • 2020-12-04 04:59

    You just want a command which gives exactly the same result as rm -rf local_repo && git clone remote_url, right? I also want this feature. I wonder why git does not provide such a command (such as git reclone or git sync), neither does svn provide such a command (such as svn recheckout or svn sync).

    Try the following command:

    git reset --hard origin/master
    git clean -fxd
    git pull
    
    0 讨论(0)
提交回复
热议问题