Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where to find changes due to `git fetch`

I didn't want to lose some information after a git pull, so I did a git fetch before. Where can I read the new modifications after a git fetch? I went to the FETCH_HEAD file, but there was nothing more than a big number.

like image 775
epsilones Avatar asked May 21 '12 00:05

epsilones


People also ask

Where is git fetch data stored?

A) Are they stored at . git/refs/remotes/origin/(branches)? By default, yes.

Does git fetch change anything?

If you do a git fetch it will just fetch all the changes in the remote repository (GitHub) and move the origin/master pointer to HEAD . Meanwhile your local branch master will keep pointing to where it has.

What comes after git fetch?

git merge origin/master should work. Since master is usually a tracking branch, you could also do git pull from that branch and it will do a fetch & merge for you. If you have local changes on your master that aren't reflected on origin , you might want git rebase origin/master to make sure your commits are 'on top'.

What is fetch changes in git?

Git Fetch is the command that tells the local repository that there are changes available in the remote repository without bringing the changes into the local repository. Git Pull on the other hand brings the copy of the remote directory changes into the local repository.


1 Answers

git fetch origin by default fetches everything from the remote named "origin" and updates (or creates) the so-called "remote-tracking branches" for that remote. Say, for the remote named "origin" which contain branches named "master" and "feature", running git fetch remote will result in the remote-tracking branches named "origin/master" and "origin/feature" being updated (or created, if they're not exist). You could see them in the output of git branch -a (notice "-a").

Now, the usual Git setup is that (some of) your local branches follow certain remote branches (usually same-named). That is, your local "master" branch follows "origin/master" etc.

So, after you fetched, to see what remote "master" has compared to your local "master", you ask Git to show you exactly this:

git log origin/master ^master 

which means «all commits reachable from "origin/master" which do not include commits reachable from "master"» or, alternatively

git log master..origin/master 

which has the same meaning. See the "gitrevisions" manual page for more info, especially the "Specifying ranges" part. Also see the examples in the git-log manual page

You're free to customize the output of git log as you see fit as it supports a whole lot of options affecting it.

Note that your local branch might also have commits which the matching remote branch does not contain (yet). To get an overview of them you have to reverse the revisions passed to git log for (hopefully) obvious reasons.

As usual, it's essential to educate yourself to understand the underlying concepts before starting to use a tool. Please do.

like image 117
kostix Avatar answered Sep 23 '22 03:09

kostix