Can you apply the same commit on a different file in a working directory?
For example, let's say I have two files, A and B. I created B as a copy of A but I want them to be very similar - I only want a couple lines different in B. Is there a way in Git to sync these changes in any way, or a more efficient way to accomplish this task?
If you can generate that difference, then you could:
- version A
- don't version B at all (and add it to your .gitignore actually)
- add a smudge script which, when reading A content git checkout would generate B.
You have the following options:
Use apply-patch-to-file. Where you can generate the patch using:
git format-patch HEAD^
And then apply using:
apply-patch-to-file -i ~/patches/0001-my-test-commit.patch
You will be prompted and asked on what files the patch should be applied.
Use directly the patch command, by creating the diff like:
git diff HEAD^ -- hello.test > ~/patch_file
Then apply the diff to a different file:
patch -p1 another_path/subdir/different_file.test ~/patch_file
You can store the diff changes in a file and patch A and B individually using this patch file.