git unadd

September 2, 2009 Alex Chaffee

Sometimes I accidentally git add files. Or more often, I do git add . and get a huge changelist and then realize I want to move certain files to a different changelist or a different branch. I could do a git reset which, absent --soft or --hard, pulls all the changes out of the index (aka dircache aka staging area) but leaves them in the filesystem (aka working tree). But wouldn’t it be nice to leave all the files in the index except the few I want to keep out?

Yes. Yes, it would. And believe it or not, git has been telling you how, every time you do a git status. Like me, you’ve probably seen this line often enough for it to be completely invisible:

#   (use "git reset HEAD <file>..." to unstage)

“Oh,” I hear the whole Internet saying, “that’s what that means.

“But why,” you continue, “instead of
documenting an obscure feature at runtime during a tangentially related operation, wouldn’t they just provide a simple git unadd command?”

Fortunately, you can just run

git config --global alias.unadd "reset HEAD"

and now you can do

git unadd foo.txt bar.txt

and only those files will be pulled out of your index. (Unfortunately, the silly overcommunication is not removed this time.)

About the Author

Biography

More Content by Alex Chaffee
Previous
On Tweed's connection woes…
On Tweed's connection woes…

We know many users have been very frustrated by Tweed lately. Tweed has had problems connecting reliably to...

Next
Jeff Sutherland on using Pivotal Tracker for Scrum Projects
Jeff Sutherland on using Pivotal Tracker for Scrum Projects

Jeff Sutherland, one of the creators of Scrum, has just posted a new blog entry in his Scrum Log: Pivotal T...

Enter curious. Exit smarter.

Register Now