1

So here is the scenario

When working locally I change up a few files by adding test data. Basically pre-populate some fields etc, to boost productivity whilst working and testing.

Obviously this needs to be undone when I commit and push just the task related changes.

How can I apply and remove this locally easily.

I have created the pre-populate as a commit that I revert, then cherry pick to reapply. However this leaves history of reverts and cherry picked commits.

Is there a a nicer way to do this?

raklos
  • 28,027
  • 60
  • 183
  • 301
  • 1
    Related: https://stackoverflow.com/questions/5308816/how-to-use-git-merge-squash – k0pernikus Mar 03 '20 at 11:15
  • 1
    Related: https://stackoverflow.com/questions/1085162/commit-only-part-of-a-file-in-git – k0pernikus Mar 03 '20 at 11:17
  • 1
    You could also `git stash` your test data and then apply it when needed. – k0pernikus Mar 03 '20 at 11:18
  • I'm personally fond of using [Stacked Git](http://www.procode.org/stgit/) for this sort of thing. I keep my debug code and configuration in a separate patch (or multiple patches) in my stack, so I can pop it off or push it on the stack whenever I need. – Hasturkun Mar 04 '20 at 11:14

1 Answers1

1

One way of doing this is to use git update-index feature. This is particularly efficient when the file in question is not often modified in the repository.

Let's consider that the file which you edit with test data is called index.asp. Instead of cherry-picking the modified version of the file, and then reverting it, keep a copy of index.asp in a separate file, either gitignored, or in a directory outside of the repository.

Copy this file over index.asp whenever necessary.

Then, to have git consider that this file is not modified:

git update-index --assume-unchanged index.asp

git will not offer anymore to stage the modifications on the file anymore.

Later, whenever you want to restore the original version of the file:

git update-index --no-assume-unchanged index.asp
git checkout -- index.asp
Mehdi
  • 7,204
  • 1
  • 32
  • 44