tags:

views:

146

answers:

3

Hi,

I delete a file in my working directory. And then I do a 'git pull'. Another person in my team modify the same file and 'git push' to the HEAD.

So when I do a 'git rebase', I get a merge conflict something like 'CONFLICT git (delete)'

My question is how can I find out what changes did the another person in the team made to the file I 'delete'?

Thank you.

+3  A: 

Git keeps a copy of the state of upstream branches in your repository as "remote tracking" branches. If you do a git branch -r you will see a list of all remote branches. Choose the one that corresponds to the branch you're working on, and do something like:

git diff HEAD^..origin/master

This should show you changes between your HEAD parent (assuming your delete was the last commit, modify as necessary) and the current state of the upstream branch.

Greg Hewgill
A: 

Create another branch from your last known good pull. Then do a Pull in the new branch from your friend. You will then be able to invstigate the log of the new branch and then know how to merge to two branches together into one then you can push to him.

Our normal development setup is to have one GIT repository that everyone rebases from. I recommend rebasing instead of pulling from a central repository. This is because if you pull from the repository then rebase to the same repository your commits that you've sent to the repository will conflict with your current branch. We generally found it easier if you have to use pull or push, to use patches instead.

Eg.. Never rebase from a repository that you've pulled from.

Chad
+2  A: 

When there is conflict during a merge or rebase, different versions of a file are available from:

  • respective branches:

    $ git show HEAD:path/to/file
    $ git show branch:path/to/file
    
  • as stages 1, 2, 3 in the index:

    $ git ls-files --unmerged  
    # ...
    $ git show :1:path/to/file
    $ git show :2:path/to/file
    

There are also tools such as "git diff --cc" and "git log --merge".

See documentation for details.

Jakub Narębski
Thank you. Is there a commit which allows me to get the whole file in the HEAD of tracking branch? I was thinking about doing 'git show :2:path/to/file > myFile' but that may change the formatting or line feed. Is there a better way?
n179911
You can use low-level "`git cat-file -p :2:path/to/file > myFile`", I think.
Jakub Narębski