Get the difference between two branches in Git

I did following (I simplified this comparing to a reality):

  • created a branch Branch1, switched to it
  • added file File1 and modified existing file File2 and commited this
  • figured out that I don’t need File1, removed it and commited this

So, the actual difference between original branch and Branch1 is only modification of File2.

  • Git: add and commit if untracked or modified?
  • IDE for eBooks to use version control
  • Open a file directly from a GitLab private repository
  • How can I get remote git branches using Node.js?
  • What happens to old commits after you use `git commit --amend`?
  • Rails 3 and Git: two applications, shared database
  • I want to get this actual difference between branches and put in Branch2. Generally speaking, I want to get rid of not necessary history of adding/removing File1.

  • compute git hash of all *uncommitted* code
  • How can I better handle commits polluting a “closed” branch in git?
  • Ignore one line in a specific file in Git
  • Managing sources across sites
  • Convert two subversion repos on googlecode to a single git repo on github
  • Can git operate in “silent mode”?
  • 2 Solutions collect form web for “Get the difference between two branches in Git”

    Let’s assume that you started on the branch master. Then you can do:

    git diff master Branch1 > ../patchfile
    git checkout Branch2    
    git apply ../patchfile

    Alternatively, if your goal is to rewrite history, then you could use an interactive rebase to squash commits.

    This is a simple git diff

    git diff --name-only SHA1 SHA2

    Where SHA1/2 are the hashes of the 2 commits at the top of each branch.

    Git Baby is a git and github fan, let's start git clone.