简体   繁体   中英

Git pull merge fetch

I'm trying to solve a problem with Git. I'm using TortoiseGit.

Basically I checked out the master-branch and without making any changes and now I want to do an update of my local repo.

As I understand there a few commands for this:

Fetch : Downloads info from the remote branch

Merge : Merges said info into the local branch

Pull : Combines above operations

However, there a few things that I see that I don't understand:

  • When I do check for modifications, it shows me that I have modified a lot of files (which I didn't). I somehow think these changes are related to changes in the remote branch
  • When I do a fetch it fetches the remote info correctly, if I then do a merge it says "Already up to date", however, if I do a pull (which supposedly combines both) I get an error saying that my local modifications would be overwritten by the merge. This surprises me, since I didn't make any local modifications. This is probably related to the previous point, but I fail to see how.

Am I misunderstanding the basics of Git, or could anyone explain this behavior to me?

There could be many things that can be considered a change. First of all the equivalent of git pull is actually.

git fetch
git merge FETCH_HEAD

Now, after you do this, you probably want to do git diff FETCH_HEAD to see what is Git considering as a difference. You might want to replace FETCH_HEAD to something more user friendly, like origin/master .

It could be line-endings, or it could be simply the modification time of the files, either way, if you want to get rid of your "modifications", you can do git reset --hard which would reset all the work tree files to what they were in HEAD, and presumably you can do the pull now.

Alternatively, you can reset directly to the latest git reset --hard FETCH_HEAD (or eg origin/master).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM