3

I have to rewrite the history of my repository because it contains some credentials. As I have to amend the root commit I followed the instructions from Git Faq:

git rebase -i allows you to conveniently edit any previous commits, except for the root commit. The following commands show you how to do this manually.

# tag the old root
git tag root `git rev-list HEAD | tail -1`
git checkout -b new-root root
# edit...
git commit --amend

# check out the previous branch
git checkout @{-1}
# replace old root with amended version
git rebase --onto new-root root

# cleanup
git branch -d new-root
git tag -d root

My problem is though that I have two branches and several tags already in the repository and I'd like that my history rewrite to apply to those too. The repo isn't public yet, so that wouldn't be a problem. I've asked a similar question before, but in that case the git rebase command was not used. Here's a basic graph of my repo:

+  master branch
|
|   + topic branch
|   |
|   |
+---+
|
|
|
+  TAG
|
+  Initial commit, the commit I'd like to amend for all branches

Is it even possible?

1

1 Answer 1

6

Use "git filter-branch" instead of git-rebase.

If you really, really feel that rebase would be better, with modern git you can use --root option to git-rebase. Or cherry-pick root commit, and then rebase on top of it, if you have older git that doesn't have this option.

3
  • Thanks Jakub. But I'm not really sure how filter-branch will help me. I have to edit code in almost 10 files, so that I pretend that the first commit had no credentials in it. I don't know how would that be possible because there's no standard format for those files. It's just code. I think it would be possible using --tree-filter, but seems way to complicated to parse the code. Aug 20, 2009 at 18:28
  • 2
    If that is the situation, simplest solution would be to create new empty branch (git symbolic-ref HEAD refs/heads/new && rm -f .git/index), and either cherry-pick root commit onto that branch and edit it using git commit --amend, then rebase rest, or use git rebase --interactive --root --onto new master. HTH. Aug 20, 2009 at 22:13
  • Thanks, I'll try them both, although the second option seems easier. Greatly appreciated. Aug 21, 2009 at 8:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.