1

Problem: A sandbox key was to be used for testing out some API calls while hacking away at the problem. I later found out that the key wasn't properly "sandboxed" and thus shouldn't have it in my commit history anywhere. How can I reapply all commits but only change that one variable?

I'm okay dealing with merge conflicts and manually going through the 20+ commits to ensure that the previous variable is correctly overwritten and doesn't show up in the git commit history.

How can I go about doing something like this? Currently I'm the only one managing the repo/code and have full control over it. The way I see it I have these options:

  1. Simply copy all the files over and check in a "fat commit". There will only be a single commit with everything as it is at the "tip" of my branch. This gets me what I want, but I loose a lot of the history.
  2. Some trick with cherry picking? Not sure how?
  3. Some trick with rebase? Not sure how?

That variable shows up across a few commits so there are bound to be merge conflicts. How can I go about this?

Here's the current state of the branches:

  • master: has the first two commits
  • myBranch: has the first two commits + additional twenty.

The 3rd commit in myBranch introduced that variable. I need to change it there first and then repeat across other commits.

PhD
  • 11,202
  • 14
  • 64
  • 112
  • 1
    Does this answer your question? [How to remove sensitive data from a file in github history](https://stackoverflow.com/questions/59850631/how-to-remove-sensitive-data-from-a-file-in-github-history) (Note the answer is not GitHub specific.) – TTT Jul 19 '21 at 21:06
  • It does address it yes...I have no idea if I can indeed use it on my machine and the impact/repercussions of it (owing to my lack of familiarity and not necessarily the shortcoming of `git-filter-repo`. – PhD Jul 19 '21 at 22:41

1 Answers1

1

Use a rebase -i (which, of course, will rewrite history):

git rebase -i revision-where-the-variable-was-badly-added~
# make sure to add the pigtail there
# the revision should show up as the first one in the list
# set that revision to 'edit'
# save and exit
# rebase should apply the revision and stop
# correct the file or files you want
git add the-file-or-files
git commit --amend --no-edit
# after this is done, you have a new corrected revision
git rebase --continue

And you should have a corrected history. You might need to force-push this to remotes because you are rewriting history.

eftshift0
  • 26,375
  • 3
  • 36
  • 60