GitCheatSheetForSVNUsers

Action Subversion git Remark
Initial checkout
svn checkout url
git clone url
git gets the entire history. (
- Use git:// url if you do NOT plan to push back upstream.
- Use https:// URL to push with user/pw prompt.
- Use user@github.com: if you have SSH keys established for easy push.
edit
Get latest version
svn update
git pull --rebase
git gets the new stuff, and tries to merge the tree.
svn merges the files, one by one
(Use --rebase to apply any local commits you have not pushed, after the pull)
edit
Commit
svn commit
git commit -a
git will commit LOCALLY. You have to push your changes back before they're published
edit
Add a new file
svn add
git add
identical
edit
Remove a file
svn rm
git rm
identical
edit
Move a file
svn mv
git mv
identical
edit
Revert a file
svn revert path
git checkout path
identical
edit
Checkout an older version of a file
?
git checkout commit-id path
git checkout branch path
 
edit
Revert a commit
svn merge -c -<rev>
svn commit
git revert commit-id;
git revert creates a new commit that removes the changes of the identified commit.
svn merge with a negative rev-id removes the rev into the working copy and requires a commit
edit
Edit last commit
 
git commit --amend
Never edit a commit once you have pushed it.
edit
Get the current status
svn status
git status
identical (use -uno option to not report "untracked" files)
edit
Reorder commits
 
git rebase -i commit-id
Use ID of last commit you don't want to change.
Never do once you have pushed to remote repo.
edit
Get a diff of changes
svn diff
git diff
identical, but git is faster and more powerful for that, afaik
edit
View history
svn log
git log
identical
edit
View history across file moves
 
git log --follow path/to/file
 
edit
Search history of a block of lines
?
git log -L start:end:file
Example: git log -L 2090:2100:lib/Foswiki.spec
edit
Search history of changes to matching regex
?
git log -L :regex:file
Example git log -L :cfg\{SystemWebName:lib/Foswiki.spec
git log -L ^:writeTypes:lib/Foswiki/Serialise/Embedded.pm
edit
Show an individual commit
svn log -v -r nnnn
svn diff -c nnnn
git show commit-id
git can show the complete commit atom with commit messages and the diff of changes using a single command. svn requires 2 commands.
edit
Apply a commit from one branch into another
svn merge -c rev
git cherry-pick commit-id
As for a revert, git commits, whereas SVN does not
edit
Annotate file with checkins per line
svn blame
git blame
identical
edit
Find which commit broke something
N/A
git bisect
git can apply checkouts between a "known good" and "known bad" release so the bad commit can be identified.
edit
Publish back your changes
N/A
git push
Everything you do in git is local, so before you push, nobody will see anything.
It pushes people to commit often, try things, then revert, and when they're ready to push, they clean their changelog
edit
Create a new branch for testing
N/A
git checkout -b Item12345
Creates a new "item" branch where you can work and commit changes that are parallel to master development
edit
Merge an item branch back
N/A
git rebase master (from item branch
git merge Item12345 (from master branch)
First catch your item branch back up with work checked into the master branch. Then switch to the master branch and merge back in the item branch work.
edit

Feel free to amend / update, I wrote that in 5 minutes smile

Thanks George for amending. Honestly, reading any crash course should be much better and worth it, but at least you have the basics all in one table. A kind of cheat sheet smile

-- OlivierRaginel - 26 Nov 2010
Topic revision: r3 - 23 Mar 2015, GeorgeClark
The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License    Legal Imprint    Privacy Policy