Git - how to selectively apply part of a patch

On a project I am looking after, one user has helpfully provided a large bunch of changes as a single patch. 80%+ is very good and should be included in the project. However there are a few changes he is proposing where I do not agree at all (He has misunderstood how one feature works). How can I with git be selective on his proposed changes. I have read about git checkout -p but don't understand how to use it, if this is the best answer.

1 Answer

  1. Normally apply patch to working tree
  2. Use git add -i to interactively select files or parts of files to stage.
    • to add whole file use 2 update
    • to review changes on selected files use 5 patch, in this mode for every change git will ask you if you want to stage it or not
  3. Commit staged changes, things you don't want will stay in working tree.
  4. If you wish to clean working tree of unwanted changes use git reset and git clean
2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like