Nick Boldt is a release engineer, formerly with IBM Rational Software Canada. As a committer for the Eclipse Modeling Project, he's automated build processes, integrated web & build systems, and designed build tools to simply and streamline building, testing, and releasing project code. Nick is a DZone MVB and is not an employee of DZone and has posted 14 posts at DZone. View Full User Profile

Git vs. SVN - Basic Commandline Syntax Reference

  • submit to reddit

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 branch git clone; cd sonatype-tycho; git checkout origin/tycho-0.10.x svn checkout
Update locally checked out files from central repo git pull svn update
List locally changes files/folders git status svn stat
Diff locally changed file git diff somefile.txt svn diff somefile.txt
Revert locally changed file* git checkout somefile.txt svn revert somefile.txt
Revert ALL local changes (except untracked files)* git reset --hard HEAD svn revert . -R
Add new file git add file.txt svn add file.txt
Add new folder recursively git add folder svn add folder
Delete file git rm file.txt svn rm file.txt
Delete folder git 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 repo git commit -m "message" file.txt; git push svn ci -m "message" file.txt
Ignore files/folders (in the current folder) echo "target
bin" > .gitignore; \
git ci -m "gitignore" .gitignore
svn propset svn:ignore "target
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.

Published at DZone with permission of Nick Boldt, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)


Geoffrey De Smet replied on Wed, 2012/03/28 - 2:31am

"svn update" is probably better done as "git pull --rebase" instead of just "git pull", to get the same behaviour as you're used to in svn, if you're working like in svn (so no forks or working on a local branch).

The problem with "git pull" is that if you have unpushed commits and new commits come in, it merges the timelines, creating something very different than you'd expect as a svn user.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.