On Fri, 29 Mar 2013 08:49:55 -0400
Paul Smith <p...@mad-scientist.net> wrote:

> On Thu, 2013-03-28 at 16:43 -0400, Dale R. Worley wrote:
> > If you think about it, in many situations "git commit -a" is what a
> > software developer wants to use.  Various trash files can accumulate
> > in a working copy; you usually only want to commit files that have
> > been specially pointed out as being valuable.
> Sure.  I'm not in any way saying "git commit -a" is doing the wrong
> thing or should be modified...?  I'm talking about the behavior of
> "git apply".  I don't really see many situations where you want to
> apply a patch and have all the modifications and deletes be processed
> but not the adds.

I think you did not get the point Dale was making.
The issue here not with `git apply` but with `git commit -a`.
I'll try to present a chain of reasoning to try to explain his point

* New commits in Git are cut from the staging area.  There's no way
  to do this otherwise.

* `git apply` itself does not modify the staging area (unless "--index"
  is passed to it).  Therefore a plain invocation of `git apply` is
  rather the same as just `patch -p1`, just `git apply` is able to use
  certain Git-specific information while reading the patch file.
  Notice that applying a patch file (no matter using which tool exactly)
  is just making changes to local files; instead of running a patch tool
  you could have just applied all the changes by hand.

* Now you have a pretty regular situation: `git apply` applied your
  patch to your work tree, and that is all -- to prepare the next
  commit, you have to decide what changes should go to it.  You do this
  by using regular tools like `git add`, `git rm`, `git reset` etc.
  Finally, when you're happy with your staging area, you run `git

* But you're using `git commit -a` instead, which, as Dale pointed out
  does not do what you possibly meant: if only automatically stages the
  local changes made to the *tracked* files.  "Tracked" is the key point
  here: since `git add` only messes with the work tree, the files it
  adds there are no different from those you could create using your
  text editor.  To cite the `git commit` manual:


    Tell the command to automatically stage files that have been
    modified and deleted, but new files you have not told git about are
    not affected.

  Do you see the point now?  What `git apply` created in your work tree
  are those "new files", and you did not tell git to track them so
  `git commit -a` ignores them.

* As Dale also pointed out, since `git commit -a` is roughly the same
  as `git add -u` followed by `git commit`, you could do what you need
  using `git add -A` followed by `git commit`.

  I think you could even create an alias for this, like

  $ git config --add alias.patch '!git apply "$1" && git add --all &&
     git commit'


You received this message because you are subscribed to the Google Groups "Git 
for human beings" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to git-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to