1

I worked on the master branch of a repository and I didn't commit the files for a while. By this time, most of the files have been modified. How can I compare and merge the files in git?

Rahul
  • 44,892
  • 25
  • 73
  • 103

1 Answers1

1

You need to commit your files first, in order to diff them to origin/master.
If you don't want to commit them on master (because you might want to update master by rebasing it on top of origin/master), you can create a tmp branch a commit there first.

git checkout tmp
git add -A
git commit -m "intermediate commit"

Then you need to git fetch origin/master, supposing origin points to your GitHub repo

Finally, you can:

  • Check all commits done on remote branch since when local branch was created:
    git diff HEAD...origin/master
  • ee the differences of what you have on your local branch but that does not exist on remote branch run:
    git diff origin/master...HEAD

See Mark Longair's excellent answer on git diff for more.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250