Tidbit: git-add –patch on a new file.

Today, I wanted to add a file to the git index interactively.

No problem!

$ echo blah > somefile
$ git-add --patch somefile
fatal: exec add--interactive failed.

It turns out there is a problem. Until git knows about the file, it can’t actually diff against it, or go into interactive patch mode. As it turns out, someone has thought ahead.

$ git add -N somefile  # adds it!

“-N” is the “–intent-to-add” flag. Whether this is a win or not is left as an exercise for the reader, but it does exist.

3 Comments on “Tidbit: git-add –patch on a new file.”

  1. I have been trying to get into Git in the last couple of weeks, but it is the little caveats that’s a bit confusing. I will get a book and see how it goes.

  2. v0n says:

    Thanks, that’s tricky but that’s what I was looking for 😉

  3. doublejosh says:

    This is nice, but now I can’t figure out how to apply this type of patch.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s