Reputation: 468
I need help understandign git pull/fetch merge, etc... I know there are a lot of articles and answers on this site, so I will put it in a context of the problem I have
So, I have this:
Remote branch "myBranch"
file A
file B
Local Branch "myBranch"
file A
file B
At this point, these 2 branches are the same
2.) I go ahead and manually create an additional file on remote branch. Imitating as if ANOTHER developer commited it So, the picture changes
Remote branch "myBranch"
file A
file B
file C *
Local Branch "myBranch"
file A
file B
Now, I know that git fetch command will "tell me" that there are changes, but will not modify my local branch. When I run git fetch, I get the following output
$ git fetch
remote: Counting objects: 4, done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 4 (delta 1), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (4/4), done.
From https://bvdevgithubvm.broadviewnet.com/internal-dev/bvn-process-history-service
0c075bc..6098e63 prototype -> origin/prototype
BUT !! I only know that there are differences.
How do I know WHAT CHANGED. Can I see the changes on remote branch BEFORE I bring it to my local branch (to my local machine)
I guess, what I am looking for, is if you know SVN world, something equivalent to being able to see svn log and see who commited what, before doing an SVN update.
This was a part 1 of the question I had. Now goes part 2, that may be viewed as independent question.
3.) So, from above I call git pull and bring the remote modification to the local branch So, the picture now is
Remote branch "myBranch"
file A
file B
file C
Local Branch "myBranch"
file A
file B
file C
At this point branches are the same.
So, I go ahead and delete the file C from my local branch. Then I commit the changes, but DO NOT push them. (yet)!!
At this point the picture is like this:
Remote branch "myBranch"
file A
file B
file C
Local Branch "myBranch"
file A
file B
Now, this is where I get confused. If I do the git fetch or git pull, output is
$ git pull
Already up to date.
I EXPECTED to know that there is something on a remote branch that makes it different. But .. I can't ?
How can I deal with this?
Now, I understand that there may be a reason for such behavior, reason that lies in git filosophy, compared to the SVN (for instance).
But, how I can deal with such a difference? How can I know that things might have changed on the remote?
Upvotes: 0
Views: 57
Reputation: 124997
How do I know WHAT CHANGED. Can I see the changes on remote branch BEFORE I bring it to my local branch (to my local machine)
Sure. Do a git diff
between the remote and local branches, as explained in How to compare a local git branch with its remote branch?.
So, I go ahead and delete the file C from my local branch. Then I commit the changes, but DO NOT push them. (yet)!!...I EXPECTED to know that there is something on a remote branch that makes it different. But .. I can't? How can I deal with this?
If you look at the log of the remote branch, you'll see a list of commits. If you look at the log of the local branch, you'll see a similar list of commits, except that the local branch has one more, namely the commit where you deleted file C
. That's a newer change than anything on the server; git tells you that your local branch is up to date with the remote branch because the local branch has every commit that's in the remote branch, and then some. Being up to date also means that you can push your changes to the remote branch with no problem; when you do, the remote will get your new commit that deletes file C
, and the repos will again match.
If you want to see how your local branch differs from the remote branch, you can again use git diff
as above.
Consider what would happen if someone else changed the remote branch. Their change might not conflict with anything you've done -- for example, they just added a file D
. In that case, your changes don't conflict with the remote branch, so you can probably still push up your change with no problem. Or, they might do something that does conflict with your version; perhaps they changed file C
. In that case, git can't know whether their change to file C
or yours is the right one to keep, so you'll need to manually resolve that conflict before you can push your changes to the remote.
Upvotes: 1
Reputation: 30212
I think you are stuck in svn world... you need to get out of it because your vision about things will be kind of broken.
First, don't think in terms of what the files look like... think in terms of what the revisions are (because that's what git actually works on)... that's why if you look around SO, you will notice that sooooo many questions are related to the way revisions are set up in different branches, not so much about what files are in there (some questions do deal with that stuff, for sure... but most are related to revisions and how to deal with them).
So, first question:
git diff --name-status remote/branchx # see what files changed
git diff remote/branchx # see the diff between both branches
git log HEAD remote/branchx # show the revisions that separate both branches
Now, about your second questions.... your local branch moved, sure... but the remote hasn't so if you try to fetch, there will be no movement of the remote references on the local repo DB (you local repo's remote pointers are already set there and also the tip of the remote branch that you are tracking is already part of the history of your branch)... that's what git is telling you.
Upvotes: 1