Log in

View Full Version : How to selectively apply parts of diff patches?


LigH
28th December 2020, 08:04
Does anyone know a GUI tool which allows me to decide which changes in a diff patch I want to apply to my local working directory? Maybe something like "Beyond Compare" or a Tortoise tool...

Beyond Compare is great to compare files in two directories, find differences, and copy each of them manually if desired. I wonder if any similar tool can not only compare two existing directories, but also one directory on one side and the result of applied diff patches on the other side. If not, I will use Beyond Compare on two working directories from different repos...

LoRd_MuldeR
28th December 2020, 16:13
Does anyone know a GUI tool which allows me to decide which changes in a diff patch I want to apply to my local working directory?

Not exactly. But the following workflow is possible:

Suppose you have a local GIT repo in "clean" state and then you manually apply some patch via "patch" command to your working directory. Now, if after applying the patch you run "Git Commit" via TortoiseGit (e.g. from Explorer context menu), this will open the Commit window and show you a list of all files that have been changed (by the patch). If you double-click any of the modified files, it will open the TortoiseGitMerge window and show you all individual changes in that file. Here you can selectively undo any changes you don't want: Just right-click the changed lines that you want to revert, on the right ("Working Tree") side, and choose command "Use other text block" from the context menu. This will restore the original lines.

Don't forget to save in TortoiseGitMerge. Once you have reverted any changes you didn't want to have, you can proceed with the commit. And then you can even "export" your commit as a new .diff file containing only the desired changes.

LigH
28th December 2020, 18:13
I won't be able to commit (R/O user, no dev); but saving instead may be the case I need.

LoRd_MuldeR
28th December 2020, 19:09
I won't be able to commit (R/O user, no dev); but saving instead may be the case I need.

Committing in Git is a purely local operation that doesn't involve the server (actually "remote" in Git jargon) at all ;)

Even if you may not have permission to push your new commits to the remote (i.e. the server), you can create as many commits in your local repo as you desire – Git is a decentralized VCS, so your local repo it is fully standalone.

You can then use "Show changes as unified diff" command in the commit log, in TortoiseGit, in order to show/save your commits as .diff files.

(And, of course, you can always fork the relevant repo on GitHub, or a similar Git hosting site, with one click. This way you can have your very own remote that you can push to)

https://i.imgur.com/NK3Jnut.png