git pull: replace local version with the remote version

后端 未结 3 589
谎友^
谎友^ 2021-01-30 17:43

There is something I don\'t understand with the git pull command. I have a foobar Git repository with two files, named f1 and f2

相关标签:
3条回答
  • 2021-01-30 18:10

    Pulling is mainly to merge your remote repository with your local one. Short answer is nothing is wrong with your git setup as your latest remote changes are already there in your local repository. If someone else push changes to the remote repository that is when pull comes handy. Those changes get pulled and merged into your local repository after you do the pull.

    0 讨论(0)
  • 2021-01-30 18:12
    git fetch origin
    git reset --hard origin/master
    

    Here is the good explanation about git pull git pull

    The git fetch command imports commits from a remote repository into your local repo. The resulting commits are stored as remote branches instead of the normal local branches that we’ve been working with. This gives you a chance to review changes before integrating them into your copy of the project.

    Command git pull <remote> fetches the specified remote’s copy of the current branch and immediately merge it into the local copy. This is the same as git fetch <remote> followed by git merge origin/<current-branch>. Since it is doing merge your commits were still there.

    After doing fetch you can reset your working copy with reset command. Hard is to ignore any changes in your local copy. git reset --hard origin/master

    0 讨论(0)
  • 2021-01-30 18:32

    To reset specific files, use git checkout:

    git checkout HEAD f1
    git checkout HEAD f2
    

    You could possibly also use wildcards (*), but I've never tried.

    Similar question: How to checkout only one file from git repository?

    Resource on git checkout: http://gitready.com/beginner/2009/01/11/reverting-files.html

    0 讨论(0)
提交回复
热议问题