Editing old objects non-interactively with git

I know how to edit an old entry manually:

$ git log --pretty=format:'%h %s'
    60e5ed9 Second commit
    0fbc8ed First commit
$ git rebase --interactive 0fbc8ed # Going back to 'First commit'
    # * $EDITOR gets fired up *
    # change 'pick 0fbc8ed' to 'edit 0fbc8ed'
$ echo 'Hello Kitteh!' > some_file
$ git add some_file
$ git commit --amend -m 'some message'
$ git rebase --continue # Go back

The problem is here:

git rebase --interactivelaunches an editor that is poorly suited for scripting. Is there a way to overcome this, i.e. Directly pass to the edit 0fbc8edteam git rebase?

Is this the idiot I'm trying, or maybe a clearer, alternative way to do this?

There is a similar question, but in my case I want to change pickto edit:

How can I automatically accept what git rebase -interactive represents to me?

+3
source share
2 answers

This is the job for "git filter-branch" and the option "-commit-filter". Take a look at the manual page, there is an example section here.

+2

:

git branch some_temporary_name # to save your initial place
git reset --hard commit_you_want_to_change
...edit...
git commit --amend -m 'some message'
git rebase your_initial_branch_name some_temporary_name
git checkout your_initial_branch_name
git merge some_temporary_name # This will be a ff since you rebased
git branch -d some_temporary_name # remove unneeded branch
+1

All Articles