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?

Answers


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.

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

(image from "Customizing Git - Git Attributes", from "Pro Git book")


You have the following options:

  1. 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.

  1. 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.


Need Your Help

Store filter greater than or equal

extjs sencha-touch sencha-touch-2 sencha-architect sencha-touch-2.1

I have a store containing scores.I need to filter out than score >10 and less than 3.

How do I parse XML web service in Swift?

xml swift nsxmlparser

I don't know how to parse in my below code..