Can you apply the same commit to another file in the 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 need a couple of lines in B. Is there a way in Git to somehow synchronize are these changes or a more efficient way to accomplish this task?

+5
source share
3 answers

If you can generate this difference, you can:

  • version A
  • don't use version B (and add it to your .gitignore )
  • add a smudge script that when reading the contents of git checkout will generate B

This is called a content filter filter using a .gitattributes declaration .

filter

(image from Git Settings - Git Attributes , from the " Pro Git book ")

0
source

You have the following options:

And then apply using:

 apply-patch-to-file -i ~/patches/0001-my-test-commit.patch 

You will be asked to indicate which files the patch should apply.

  1. Use the patch command directly, creating diff as:

     git diff HEAD^ -- hello.test > ~/patch_file 

Then apply diff to another file:

 patch -p1 another_path/subdir/different_file.test ~/patch_file 
+1
source

You can save diff changes to the file and patch A and B individually using this patch file.

0
source

Source: https://habr.com/ru/post/1236770/


All Articles