How to incorporate certain files from a commit Papers in systems nice about dynamic conservatism


I recently came across a situation in which I wanted to carry out one git cherry-pick Operation, but I just wanted to deduct certain files from the commit. The reasons for this themselves are not so important – I just wanted to make a note for myself and others struggle with it.

The general approach is the use git show To create a diff with the desired files and to treat this as a patch for the application.

The general format is:

git show (sha) -- (file1 ... filen) | git apply --index -

You can specify entire directories, not just files.

The --index Argument on git apply will essentially make the changes to your work files and then carry out one git add so that you are ready to sign. When you let go --indexYou just have to do one git add If you are ready to sign.

For example:

git show 547f82a7a5 -- src/vendor-driver-refactored/sensirion_common.c | git apply --index -

Now you have to commit yourself. You can write a new commit at this time. But you can also use the commit message, the author information and the time stamp from the other commit with the reuse -C or -c Use flags git commit. The “big one CThe variant uses the fortress information directly, whereby the “Little C” variant opens the editor so that you can adjust the commit message if necessary.

git commit -c 547f82a7a5
# opens an editor
-C <commit>
--reuse-message=<commit>

Take an existing committee object and use the log message and the authors information (including the timeline) when creating the commit.

-c <commit>
--reedit-message=<commit>
Like -c, but with -c, the editor is called up so that the user can continue to edit the commit message.

References



Source link