2

I like to apply some changes to my project that help with my eccentric workflow (e.g. I make some project structure changes, delete some excessive logging lines, etc), but I don't want the changes showing up in my git history when I create a branch for merging. The effort to manually rewrite history is too much for the number of times I have to do this.

Is there a way to apply a diff file (e.g. produced from format-diff) such that the files are edited on disk but the history and index do not notice the differences?

The only hack I can think up is to apply non-git .diff files with patch and add the files to git update-index --assume-unchanged foo/bar but is there a better - more "git" - way?

fommil
  • 5,757
  • 8
  • 41
  • 81
  • 1
    Make the changes on another branch. Branches are basically free, but if you just want to try them out temporarily, use a detached HEAD which drops even the cost of the branch itself (check out the branch again and any commits you made using the detached HEAD drift away and get gc'ed in ~30 days). If you need to do this often, just keep a reference to a commit with these changes in it, so that you can detach+cherry-pick+test+checkout-to-discard any time you want to test this way. – torek Sep 05 '16 at 11:16
  • Hi Torak, that's what I've tried. I'm seeking a better way that doesn't involve so much manual management of branches, without leaving git. I've moved onto a script that sets/unsets unchanged status and applies a patch, but it's not ideal. – fommil Sep 06 '16 at 07:40

1 Answers1

-1

The effort to manually rewrite history is too much for the number of times I have to do this.

But this does not have to be any work at all. With a tiny bit of discipline on your part, this can actually be semi-automated.

What I do when adding changes to a branch like extra debug that should not be included in the final result is to mark the commit message in a way that stands out very clearly when doing an interactive rebase, like for instance

pick fdbd12a Mininmal main.c
pick 21e3d6f hello world with arg support
pick a62ebac ========= DEBUG: print argc ========
pick 3160605 Use EXIT_SUCCESS
pick 0ec0ac6 constify message

(see this answer for more explanation).

To remove the non-final commits I can in the vi editor filter with "!grep -v =======" and they are gone with no mental effort required1. So you only need to be a little bit disciplined and mark the commit messages in an obvious way.

With this approach you can keep working on one branch with all your debug/final-exclude-changes included while developing. The branch can by the way be rebased without any additional trouble.


1 Excluding commits might trigger merge conflicts, in which case I recommend using KDiff3 to resolve them.

Community
  • 1
  • 1
hlovdal
  • 26,565
  • 10
  • 94
  • 165
  • Sorry, this is not answering the question I asked. Have you heard the phrase "telling granny how to suck eggs"? – fommil Sep 07 '16 at 07:30