Pivotal Labs

Main menu

Skip to primary content
Skip to secondary content
  • About
  • Case Studies
  • Team
    • Executives
    • Locations
      • San Francisco (HQ)
      • Boston
      • Boulder
      • Denver
      • London
      • Los Angeles
      • New York
  • Community
    • Blogs
    • Tech Talks
    • Events
  • Careers
    • Lifestyle
    • Principles & Practices
    • Benefits
    • FAQ
    • Apply
  • Tools
  • Contact
    • Press Room
    • Press Releases
    • In The News
    • Press Kit
  • All
  • Labs
  • Standup
  • Tracker

git unadd

Alex Chaffee
Wednesday, September 2, 2009

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.)

  • 0 Shares
  • Share on Facebook
  • Share on Twitter

8 Comments

  1. Alex Chaffee says:

    See also GitFaq: [Why is "git rm" not the inverse of "git add"?](http://git.or.cz/gitwiki/GitFaq#Whyis.22gitrm.22nottheinverseof.22gitadd.22.3F)

    September 2, 2009 at 3:28 pm

  2. Sebastian says:

    Any particular reason you didn’t go for “remove”? “unadd” seems almost as obscure as “reset HEAD”.

    September 2, 2009 at 5:51 pm

  3. Alex Chaffee says:

    “remove” is an expansion of “rm” and means something else altogether in Gitistan — see that FAQ link in my earlier comment. I agree that git terminology is hazy at best but I’m not in a position to fix it, and after [browsing Google](http://www.google.com/search?q=git+unadd) it seems many others share my intuition that you’d call undoing an add an “[unadd](http://kerneltrap.org/mailarchive/git/2006/2/1/200270)”.

    September 2, 2009 at 6:10 pm

  4. Tom Ward says:

    Nice little trick, now added to my aliases. Thanks for sharing.

    September 2, 2009 at 11:49 pm

  5. Brandon Thomson says:

    Thanks, this is useful… Now I’m worried my custom git configs might end up as long ad my vim config!

    September 4, 2009 at 12:11 am

  6. grosser says:

    I got this aliased to git unstage and more @ http://github.com/grosser/dotfiles/blob/master/gitconfig ;)

    September 8, 2009 at 10:38 pm

  7. Jack Dempsey says:

    Cool stuff Alex. For those who may not know, HEAD is the default:

    “
    Commit to make the current HEAD. If not given defaults to HEAD.”

    So, its really just typing unadd instead of reset. I can see how that will work nicely and all, but sometimes I find myself in a land without personal aliases and wishing I hadn’t used so many. ymmv.

    September 8, 2009 at 10:48 pm

  8. Mark Wilden says:

    Even when I’m on a system without all my pretty aliases, it’s useful to know that git is case-insensitive by default, so you can type ‘head’ instead of ‘HEAD’.

    October 15, 2009 at 10:05 am

Add New Comment Cancel reply

Your email address will not be published.

Alex Chaffee

Recent Posts

  • Code Monkey
  • RubyGems Warningitis Outbreak
  • Upgrading your Rakefile from RSpec 1.3 to RSpec 2
Subscribe to Alex's Feed

Author Topics

ruby (14)
gem (5)
ruby on rails (24)
erector (2)
rspec (4)
activerecord (4)
database (3)
sinatra (1)
postgresql (1)
css (1)
html (1)
git (2)
mac (5)
java (3)
agile (12)
iphone (1)
migrations (1)
fun (5)
dot (1)
graphing (1)
subversion (1)
test (1)
demeter (1)
puzzler (1)
  • About
  • Case Studies
  • Team
  • Community
  • Careers
  • Tools
  • Contact
  • Labs
  • Events

Contact Us

contact@pivotallabs.com
+1 415-77-PIVOT
TwitterLinkedInFacebook

Pivotal Tracker

Tracker is the award-winning agile project management tool that enables real-time collaboration around a shared, prioritized backlog.
Visit pivotaltracker.com >