I was reading this (old) posting on GIT and read the following:
By using
git add --p
, you can choose which patches from a file you want to include for checkin.The result is that the开发者_运维问答 index contains a version of the file which is not in your working copy.
My question is twofold:
- Is this still true?
- How do I bring the changes back in from index after I've done this?
I think that you might be misunderstanding what git add -p
does.
git add -p
is something which you can use if you have files modified in your working copy, but for which you only want to apply some of the difference from those files to your index. Thus, you wind up with something in your index which only contains some of the changes that you have in your working copy. It doesn't have anything to do with a patch file; it just lets you choose parts of the difference between your working copy and HEAD to apply to the index.
If you want to apply a patch file to your index and/or working copy, use git apply
. By default this will just apply changes to your working copy, and you will have to add them to the index using git add
; however, you can use --index
to also add them to the index, or --cached
to only add them to the index, without modifying the working copy.
If you have a large number of patches to apply in a mailbox, you can use git am
to apply a whole series of patches at once.
精彩评论