Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
git rebase --abort

Advanced Git Topics

Diff between branches

Git offers a couple of great commands for comparing branches. To get a comparison of branches in a "status" type format:

Code Block

git diff --name-status branch1..branch2

Will give you output something like:

Code Block

M       config/boot.rb
M       config/database.yml
M       config/deploy.rb

Now that you have a list of files, you may wish to get a diff of a specific file:

Code Block

git difftool branch1:FILE.txt branch2:FILE.txt

This will open the configured mergetool. Note the mergetool and difftools can be setup to use different programs. If mergetool isn't configured, git will use difftoll as a fallback.

Cherry-Picking

When developing a fix or feature across multiple branches, you often cannot just merge one branch onto another. Think of a fix that needs to be applied to versions 1.0, 2.0 and 2.2. Merging would bring in more than your one fix. In this scenario cherry-picking is the answer. Basically it's capturing a patch-file of one commit and applying it to another branch to create a new commit.

...

Code Block
git stash save "My Message Here"

Stash is actually a LIFO queue. You can stash multiple times and "pop" them back off. Stash a couple times and issue the following to see the stash queue

Code Block

git stash list

This should result in a list like the following:

Code Block

stash@{0}: On master: My Message Here
stash@{1}: WIP on master: 01fbfb5 Object Factory and PentahoSystem overhaul.

You can apply and remove any stash in any order by passing it's ID to pop or apply:

Code Block

git stash pop stash@{1}

Most people just the pop command to apply a stash and remove it, but you can simply apply a stash to a branch and keep it around in the list if you want to apply it to multiple branches (cheap cherry-pick / reset)

Reflog

Reflog is the command to see all changes to branch pointers. This will include commits, resets, etc.

...