17 August 2012

undo add in git

Git is awesome. I like using Git.

It works smoothly with Netbeans, IntelliJ IDEA or even from command line .
[Yes , I know .Eclipse was first, that supported Git ,but as always for this shitware,it supported,but it didn't work and I    endup doing everything manually anyway (like with maven stuff and most things in Eclipse). I used only early versions of plug-in for Elcipse,so i guess it must wok better these days.]

Anyway. This note is about Git and solution to how to undo add.
So as you discover you can do lots of amazing things ,but you can easly add files ,BUT  for some mystirious reason.... you cannot just type  undoadd filename to undo your mistake. It seems author strongly believe,that we know what we doing with stuff in git and think,that if we add something,then ...it is final.
So what to do when you add something,but you change mind ?How to manually add "undo" add ?

You need add "undoadd" command to your config,by add alias ... how?You have a 2 option.

a) You can edit your global git setting file
(usually is in user directory,
for example in windows XP
C:\Documents and Settings\JuicyJuiceMan\.gitconfig (where JuicyJuiceMan is a your user login)
find [alias] ... or if you don't have the just copy 2 lines below

[alias]
 undoadd = reset HEAD


 undoadd - name of your command (can be unadd or whatever you like)

b)
in git bash you can type:
git config --global alias.undoadd "reset HEAD"

from now to undo add you can simply type : (example for un add fail.file)
undoadd fail.file
Who knows,maybe in far away future authors will add this such cutting-edge command to program.

For other undoing things in git, look to chapter 2.4  "Git-Basics-Undoing-Things" in  book: Pro Git
which is avaliable for free here: http://git-scm.com/book/en/Git-Basics-Undoing-Things