Home > Software design >  Applying a change to all changes in a git commit
Applying a change to all changes in a git commit

Time:06-16

I am not sure that what I want is possible, but basically I did a commit to my app where I changed some occurrences of "\\" to "/" let's call this Commit 1.
but now a want to change all of these occurrences from "/" to "$$", so I want to apply a change to the changes that happened in commit 1 only without altering any of the occurrences of "\\" that was not changed to "/" in commit 1

CodePudding user response:

The best way to do this is the simple-minded manual way. Do a diff between commit1 and its parent. Now you have a list of all the lines where you changed "\\" to "/". Using that list as a guide, change the "/" in each of those lines to "$$". Add-and-commit.

CodePudding user response:

Trying to get clever :

if your changes occurred at commit B :

...*--*--*--A--B--*--*--H <- master

Running :

  • git diff B A will produce a patch that would replace / with \\ (e.g : revert commit B),
  • git diff B A -G'/' will only keep the files where the diff includes a / (so with some luck, it will reduce the size of the generated diff).

You can try to :

  1. store that diff in a file :
git diff B A -G'/' > my.patch
  1. edit that file in a text editor, to turn it from a patch which replaces / with \\ to a patch which replaces / with $$

  2. apply this edited patch on your current code base :

git apply my.patch

Depending on how the other changes were applied after commit B, the number of generated conflics may be reasonable to handle by hand.

  •  Tags:  
  • git
  • Related