Software Development

Git vs. SVN – Commandline Syntax Reference

Learning the git workflow takes a bit of brain retraining, but since I’ve been using SVN almost entirely via commandline (because Subversive sucks and locks up my Eclipse when I try to use it for anything beyond synching/updating/committing a handful of files), adopting git’s commandline syntax is reasonably similar. Consider these simple operations:

Initial checkout from existing repo for a given branchgit clone http://github.com/sonatype/sonatype-tycho.git; cd sonatype-tycho; git checkout origin/tycho-0.10.xsvn checkout http://anonsvn.jboss.org/repos/jbosstools/branches/jbosstools-3.2.0.Beta1/
Update locally checked out files from central repogit pullsvn update
List locally changes files/foldersgit statussvn stat
Diff locally changed filegit diff somefile.txtsvn diff somefile.txt
Revert locally changed file*git checkout somefile.txtsvn revert somefile.txt
Revert ALL local changes (except untracked files)*git reset –hard HEADsvn revert . -R
Add new filegit add file.txtsvn add file.txt
Add new folder recursivelygit add foldersvn add folder
Delete filegit rm file.txtsvn rm file.txt
Delete foldergit rm -r folder (non-recursive by default; use -r to recurse)svn rm folder (recursive by default; use -N to not recurse)
Commit changed file to central repogit commit -m “message” file.txt; git pushsvn ci -m “message” file.txt
Ignore files/folders (in the current folder)echo “target

*.class

bin” > .gitignore; \

git ci -m “gitignore” .gitignore

svn propset svn:ignore “target

*.class

bin” .; \

svn ci -N -m “svn:ignore” .

Obviously you can do a lot more w/ Git than with SVN (like stashing local changes temporarily), but for the sake of simply moving from a VCS to a DVCS and being able to continue to work the same way you already do, the above table should provide a good introduction.

Reference: Git vs. SVN – Basic Commandline Syntax Reference from our JCG partner Nick Boldt at the DivByZero blog.

Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Back to top button