GitCheatSheet

Differences between revisions 1 and 2
Revision 1 as of 2009-03-05 16:56:40
Size: 3078
Editor: ip-64-32-163-20
Comment:
Revision 2 as of 2009-03-05 18:25:51
Size: 3157
Editor: ip-64-32-163-20
Comment:
Deletions are marked like this. Additions are marked like this.
Line 4: Line 4:
Line 5: Line 6:
Line 6: Line 8:
Line 7: Line 10:
Line 8: Line 12:
Line 9: Line 14:
Line 12: Line 18:
Line 14: Line 21:
* Sets of commits * == Sets of commits ==
Line 16: Line 24:
Line 17: Line 26:
Line 18: Line 28:
Line 22: Line 33:
* Commits where one is not an ancestor of the other * == Commits where one is not an ancestor of the other ==
Line 37: Line 48:
* Merging, etc * == Merging, etc ==
Line 44: Line 55:
Line 45: Line 57:
Line 47: Line 60:
Line 48: Line 62:
Line 53: Line 68:
* Using remote repositories * == Using remote repositories ==
Line 56: Line 71:
Line 57: Line 73:
Line 58: Line 75:
Line 59: Line 77:
Line 60: Line 79:
Line 63: Line 83:
Line 68: Line 89:
* rebasing * == rebasing ==
Line 72: Line 93:
----------------------------------------------------------------
Line 73: Line 95:
---------------------------------------------------------------- == Assorted ==
Line 80: Line 102:
git reset --hard HEAD^ - throw away all changes and one more
git reset --hard HEAD^ - throw away the last commit that was made
Line 89: Line 112:
Line 92: Line 116:

Concise Listing of Git use cases

git show c82aa23 (the commit)

git show foobranch (tip of the foobranch branch)

git show HEAD (tip of current branch)

git show HEAD^ (parent of head, previous state of the project)

git show HEAD~1 (same as HEAD^)

git show HEAD (grandparent)

git show HEAD~2 (same as HEAD)

To see whether a particular commit is in a particular branch:

git log --pretty=one <branch> | grep sha1

Sets of commits

git log v2.5..v2.6 # commits between v2.5 and v2.6

git log v2.5.. # commits since v2.5

git log --since="2 weeks ago" # commits from the last 2 weeks

git log v2.5.. Makefile # commits since v2.5 which modify Makefile


Commits where one is not an ancestor of the other

If the tips of the branches "stable-release" and "master" diverged from a common commit some time ago, then

git log stable..experimental

will list commits made in the experimental branch but not in the stable branch, while

git log experimental..stable

will show the list of commits made on the stable branch but not the experimental branch.


Merging, etc

git pull /home/bob/myrepo master # merge changes from bob's master branch onto my current branch

(pull fetches and merges)

git fetch /home/bob/myrepo master

git log -p HEAD..FETCH_HEAD

(two dot form - 'everything reachable from FETCH_HEAD, excluding anything reachable from HEAD') or

gitk HEAD...FETCH_HEAD

(three dot form - 'show everything reachable from either, exclude anything reachable from both) (fetch and look at everything between HEAD and head of what bob had)


Using remote repositories

git remote add bob /home/bob/myrepo

git fetch bob

git log -p master..bob/master # list of changes since bob branched from my master

git merge bob/master # merge changes in bob into my master branch

git pull . remotes/bob/master # same as the last one

(git pull always merges into the current branch)

git push --tags remotename localbranch:remotebranch

(creates remote branch)


rebasing

git rebase master topic # place all new commits in topic on top of master


Assorted

gitk --since="2 weeks ago" drivers/

git diff v2.5:Makefile HEAD:Makefile.in # diff different files in different commits

git reset --hard HEAD - throw away all changes

git reset --hard HEAD^ - throw away the last commit that was made

git grep "foo" existingtagname

git diff tagname HEAD

git branch newbranchname existingtagname


Accessing remote branch lpia

git clone --reference /home/sconklin/src/reference-trees/linus git://kernel.ubuntu.com/ubuntu/ubuntu-hardy.git hardy-kernel

git checkout origin/lpia

KernelTeam/GitCheatSheet (last edited 2010-06-28 23:45:36 by c-76-105-148-120)