Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I do the reverse of gitk's "Write commit to file"?

I have written a commit to a file from gitk by right-clicking the commit and selecting "Write commit to file".

How do I apply the commit from this file? I can do git apply, git add and git commit combo, but isn't there a one-step command to just take the output (with the commit message and meta-data) and commit it as it is?

like image 310
Šimon Tóth Avatar asked Apr 19 '12 14:04

Šimon Tóth


2 Answers

No-one seems to have provided an actual answer to the question, so here's what I found from https://github.com/sinsunsan/archiref_wiki/wiki/Git-howto

patch -p1 < patch-file

This takes the patch file produced by 'Write commit to file', tells it to ignore the first level of path (-p1) i.e. a/, b/ in the file, and apply to the current files on disk. The result is then in your working tree, and can be committed as a new commit:

git commit -am'Commit message here please.'
like image 143
Neek Avatar answered Oct 23 '22 05:10

Neek


I'm using Linux, but I think I see what you're talking about. In gitk there is a "Write commit to file" option when right-clicking a commit, which brings up a dialog that performs the command git diff-tree --stdin -p --pretty by default.

git apply is only for applying diffs, i.e. it won't create the commit object so that shouldn't be used. git am should be the correct tool for performing this operation, as it creates commit objects. However, it doesn't understand the format output by the above command, and creates the error you are seeing.

The easiest option is probably to create the patch using a format git am understands using git format-patch instead of git diff-tree. There may be a way to coerce git am into understanding the git diff-tree format, but I don't do patches much so am not aware of it offhand.

like image 33
Abe Voelker Avatar answered Oct 23 '22 03:10

Abe Voelker