Reverting a file in ‘git’
I have just begun to learn ‘git’ and understand the motivation behind distributed SCMs. One of the great powers of git, in addition to the fact that it is super fast is its excellent merging and branching capabilities. I use perforce at work and SVN at home and I have used CVS as well so to tune your head around a distributed SCM is challenging and requires some reorientation.
We use perforce at work and created merged 104 branches in the last year (all experimentation and execution is done in branches with the trunk or mainline being stable) - I think the merging in perforce is quite good but too slow, plus it costs money. SVN and CVS are different stories however - merging is downright painful and requires endless hours on manual merges and testing. So I was interested in seeing what GIT has to offer.
Installation and creation of a repository was quite straight forward. I checked in a project and was functional.
Next I tried to edit a file and tried to revert it.
pranay@pranaydesktop:~/dev/workspace/grails/testApp/web-app/js/prototype$ vim prototype.js pranay@pranaydesktop:~/dev/workspace/grails/testApp/web-app/js/prototype$ git status # On branch master # Changed but not updated: # (use "git add..." to update what will be committed) # (use "git checkout -- ..." to discard changes in working directory) # # modified: prototype.js # no changes added to commit (use "git add" and/or "git commit -a") pranay@pranaydesktop:~/dev/workspace/grails/testApp/web-app/js/prototype$ git revert prototype.js fatal: Cannot find 'prototype.js' pranay@pranaydesktop:~/dev/workspace/grails/testApp/web-app/js/prototype$
Not what I really expected. A little research made me learn is “revert” in git is actually a “rollback” of a checked in change. This was a little counter intuitive - I would have preferred it being called “rollback” instead.
The real way to actually revert a file is check it out again.
pranay@pranaydesktop:~/dev/workspace/grails/testApp/web-app/js/prototype$ git checkout prototype.js pranay@pranaydesktop:~/dev/workspace/grails/testApp/web-app/js/prototype$ git status # On branch master nothing to commit (working directory clean) pranay@pranaydesktop:~/dev/workspace/grails/testApp/web-app/js/prototype$ pranay@pranaydesktop:~/dev/workspace/grails/testApp/web-app/js/prototype$
Hopefully I will never forget this.
