Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create Git patches for two files across several renames

I want to move two files from one repository to another. The files were originally added as:

  1. /src/init/Price.cs
  2. /tests/init/PriceTests.cs

The two files were later renamed to:

  1. /src/init/PriceValue.cs
  2. /tests/init/PriceValueTests.cs

And then moved to:

  1. /src/moved/PriceValue.cs
  2. /tests/moved/PriceValueTests.cs

I've tried to go by this description to create a set of patches for these files, but I'm unsure how to pass in the six different paths the files have existed on.

I've managed to find all the commit IDs affecting PriceValue.cs (across renames and moves), but passing those IDs to Git fails with the following error message:

$ git format-patch -o /tmp/pricevaluepatches $(git log --all dfeeb 6966b 9f882 …)
-bash: /usr/local/bin/git: Argument list too long

So, how do I create a set of patches for this that only contains the changes to the mentioned files, but contains it across one rename and one move of each file?

like image 453
Asbjørn Ulsberg Avatar asked Apr 27 '17 11:04

Asbjørn Ulsberg


People also ask

How do I create a patch format in git?

In order to create Git patch file for a specific commit, use the “git format-patch” command with the “-1” option and the commit SHA. In order to get the commit SHA, you have to use the “git log” command and look for the corresponding commit SHA.

How do I create a patch for one file?

You click on Actions->Create Patch... You click on "Working Copy Changes" You can now select all files that should be included into the patch file.

How do I create a patch in git bash?

To create a patch file from one commit to other i.e a patch file in which changes include all the commits from starting commit and end commit. It is done by git diff starting-commit-sha ending-commit-sha myPatch. patch, where “myPatch” is the patch name and the starting and ending sha of the commits are included.


1 Answers

You can get the patches of a few specific files but not earlier than commit sha1 using

git format-patch sha1 -- file1 file2 ...

Any of the files can be an old file (prior to a rename) or an existing file.

If you want all commits until commit sha1 you can use

git format-patch --root sha1 -- file1 file2 ...

So in your case, all commits until now (HEAD) of your six files:

git format-patch --root HEAD -- /src/init/Price.cs /src/init/PriceValue.cs /src/moved/PriceValue.cs /src/init/PriceTests.cs /src/init/PriceValueTests.cs /src/moved/PriceValueTests.cs
like image 71
Nils Werner Avatar answered Sep 30 '22 13:09

Nils Werner