Adam @ Heroku
a tornado of razorblades

More Git Techniques

Posted by Adam Wiggins on May 15, 2008 at 05:28 PM

In the spirit of Graeme Mathieson's git techniques, here are a few of my favorites, with their svn equivalents for reference.

Restore a file to repository version
  svn: rm file; svn up file
  git: rm file; git checkout file

See what commits would be pulled on an update
  svn: svn stat -u
  git: git fetch; git log HEAD..origin/master

See what code changes would be pulled on an update
  svn: svn diff -rHEAD
  git: git fetch; git diff HEAD..origin/master

Grab one commit without any of the commits around it:
  svn: svn diff -rN1:N2 > my.patch; scp my.patch other.server; ssh other.server "patch < my.patch"
  git: git fetch; git cherry-pick [commit-hash]

Revert a commit
  svn: svn merge -rN2:N1; svn commit -m "reverted commit N2"
  git: git revert [commit-hash]

Set some changes aside to work on something else
   svn: cd ..; mv myproj myproj_stash; svn co svn+ssh://server/myproj
   git: git stash

Discard local changes
  svn: svn revert -R .
  git: git reset —hard HEAD

Edit recent commits
  svn: echo "Oops."
  git: git rebase -i HEAD~5
Tags: git
Hierarchy: previous, next

Comments

There are 3 comments on this post. Post yours →

Alissa

Completely besides the point I know, but.

> Restore a file to repository version > svn: rm file; svn up file > git: rm file; git checkout file

Wouldn't "svn revert file" be more efficient?

> Grab one commit without any of the commits around it: > svn: svn diff -rN1:N2 > my.patch; scp my.patch other.server; ssh other.server "patch git: git fetch; git cherry-pick [commit-hash]

Am I missing something? Wouldn't "svn merge -rN1:N2" work?

@Alissa - You're totally messing up my attempt to strawman Subversion. :)

Restore a file to repository version

git: git checkout -f file

Set some changes aside to work on something else:

svn: svn diff > /tmp/path ; svn revert -R .

Post a comment

Required fields in bold.