Sei sulla pagina 1di 1

Commands Sequence

Git Cheat Sheet the curves indicate that the command on the right is usually
executed after the command on the left. This gives an idea of
http://git.or.cz/ the flow of commands someone usually does with Git.

Remember: git command --help

Global Git configuration is stored in $HOME/.gitconfig (git config --help)

CREATE BROWSE CHANGE REVERT UPDATE BRANCH COMMIT PUBLISH

init status reset pull checkout commit push


clone log checkout fetch
show revert merge branch format-patch
diff am
branch
Create Concepts
From existing data
cd ~/projects/myproject
Git Basics
git init master : default development branch
git add . origin : default upstream repository
HEAD : current branch
From existing repo HEAD^ : parent of HEAD
HEAD~4 : the great-great grandparent of HEAD
git clone ~/existing/repo ~/new/repo
git clone git://host.org/project.git
git clone ssh://you@host.org/proj.git Revert
Show Return to the last committed state
git reset --hard
Files changed in working directory
! you cannot undo a hard reset
Update Publish
git status Revert the last commit
Fetch latest changes from origin Commit all your local changes
git revert HEAD Creates a new commit
Changes to tracked files git fetch git commit -a
git diff Revert specific commit (but this does not merge them).
git revert $id Creates a new commit
Pull latest changes from origin Prepare a patch for other developers
What changed between $ID1 and $ID2 git pull
Fix the last commit git format-patch origin
git diff $id1 $id2 (does a fetch followed by a merge)
git commit -a --amend
History of changes (after editing the broken files) Apply a patch that some sent you Push changes to origin
git log git am -3 patch.mbox git push
Checkout the $id version of a file
History of changes for file with diffs (in case of a conflict, resolve and use
git checkout $id $file git am --resolved )
git log -p $file $dir/ec/tory/ Mark a version / milestone
Who changed what and when in a file Branch git tag v1.0
git blame $file
Switch to the $id branch
A commit identified by $ID git checkout $id Finding regressions To view the merge conclicts

Resolve Merge Conflicts


git show $id git bisect start (to start) git diff (complete conflict diff)
Merge branch1 into branch2

Useful Commands
git bisect good $id ($id is the last working version) git diff --base $file (against base file)
A specific file from a specific $ID git checkout $branch2 git bisect bad $id ($id is a broken version) git diff --ours $file (against your changes)
git show $id:$file git merge branch1 git diff --theirs $file (against other changes)
git bisect bad/good (to mark it as bad or good)
Create branch named $branch based on git bisect visualize (to launch gitk and mark it)
All local branches
the HEAD git bisect reset (once you're done)
To discard conflicting patch
git branch git branch $branch
(star '*' marks the current branch) git reset --hard
Create branch $new_branch based on Check for errors and cleanup repository git rebase --skip
branch $other and switch to it git fsck
Cheat Sheet Notation git checkout -b $new_branch $other git gc --prune
After resolving conflicts, merge with
$id : notation used in this sheet to represent either a Search working directory for foo()
commit id, branch or a tag name
Delete branch $branch git add $conflicting_file (do for all resolved files)
git branch -d $branch git grep "foo()" git rebase --continue
$file : arbitrary file name
$branch : arbitrary branch name Zack Rusin
Based on the work of:
Sébastien Pierre
Xprima Corp.

Potrebbero piacerti anche