Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git, edit root commit for all branches

Tags:

git

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?

like image 763
Ionuț G. Stan Avatar asked Apr 08 '26 10:04

Ionuț G. Stan


1 Answers

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.

like image 50
Jakub Narębski Avatar answered Apr 10 '26 03:04

Jakub Narębski



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!