Tuesday, February 14, 2012


Username and Email
git config --global user.name "Pedro Abrantes"
git config --global user.email daniel.abrantes@gmail.com
git config --global diff.tool meld
git config --global merge.tool meld
git config --global push.default matching

Use colors in git
git config color.ui true

Pretty Log
git config format.pretty oneline

Get latest from server
git fetch origin
git merge origin/"branch"

Delete branch
git branch -d branch
git push origin --delete branch

View differences between branches
git difftool master..devel

View differences between local file and other branch
git difftool  other_branch -- path_to_file
git difftool  other_branch path_to_file

View differences between branched for one specific file
git difftool  one_branch other_branch -- path_to_file
git difftool  one_branc..other_branch path_to_file

Get an archive from differences between branches
git archive -o update.zip version3.1.18a $(git diff --name-only version3.1.18_merged )

How do I create a new git branch from an old commit and checkout it?
git checkout -b <name> <oct>

Checkout file from previous commit

First get the file back from one commit before:

git checkout HEAD~1 path/to/file.ext
Then commit it:

git commit -a -m 'Retrieved file from older revision'
If only the changes to that file where present in the last commit, you can even use git-revert:

git revert HEAD
I think it would be better to make this a separate commit, because it tells you exactly what you've reverted, and why. However, you can squash this into the previous commit by using the --amend switch to git-commit.

Checkout a remote branch without locally created
git checkout -t origin/branch
git fetch origin
git checkout -b test origin/test

Check files on disk
git fsck-objects --full

To see the changes between the working directory and the index. This shows what has been changed, but is not staged for a commit.

git diff

To see the changes between the index and the HEAD(which is the last commit on this branch). This shows what has been added to the index and staged for a commit.

git diff --cached

To see all the changes between the working directory and HEAD (which includes changes in the index). This shows all the changes since the last commit, whether or not they have been staged for commit or not.

git diff HEAD

To view only the difference in patch mode
git format-patch branch1..branch2

to make a single patch use:

git format-patch branch1..branch2 --stdout > my_new_patch.diff
and apply
git am < my_new_patch.diff

To squash all commits since you branched away from master, do
git rebase -i master

Post a Comment

bootstrap_fonts_woff: inputs: - '%kernel.root_dir%/../vendor/twitter/bootstrap/fonts/glyphicons-halflings-regular.woff' output...