git

Section: Misc. Reference Manual Pages (pj)
Updated: 10 July 2014
Index Return to Main Contents
 

Comparing branches

To compare two branches:
    git diff master..develop

To show all commits in develop that aren't in master:
    git log develop ^master --no-merges

To diff by date:
    git log 'master@{3 days ago}' master
    git log 'master@{3 days ago}' master -- path/to/file

 

Old history

To see an old version of something:
    git show HEAD~1:path/to/file

Here ~1 means "1 revision before HEAD"

To find the commit in which you removed an object:
    git log -n 1 -- <filename>

To get it back:
    git checkout <commit>^ <filename>

To use git blame but only show changes prior to an old commit:
    git blame <commit>^ -- <filename>

 

Remotes

To see everything on a remote repository:
    git remote show origin

To enable access to new remote branches, you might have to do this:
    git fetch origin

To create a local branch based on a remote branch:
    git checkout -b <branch> origin/<branch>

http://stackoverflow.com/questions/1783405/git-checkout-remote-branch

To set a local branch to track a remote branch:
    git branch --set-upstream foo origin/foo

 

Erasing

To erase the last commit without altering your index or checkout:
    git reset --soft HEAD~1

To reset your checkout to origin:
    git fetch origin && git reset --hard origin/master

 

Security

To run git with a different ssh key:
    ssh-agent bash -c 'git add <private-key>; git <cmd>'


 

Index

Comparing branches
Old history
Remotes
Erasing
Security

This document was created by man2html, using the manual pages.
Time: 16:38:23 GMT, March 03, 2017