Editing old commits non-interactively with git

I know how to edit an old commit 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 here:

  • Git: Why is only 1 merge showing in my history when I have done several?
  • Svn2git: Add revision number to git commit title
  • Git(hub): change branch?
  • git - Including submodules into the main repository
  • How can I tell which remote “parent” branch my branch is based on?
  • How to use jgit to clone the existing repositories to new github instance?
  • git rebase --interactive fires up an editor, which is kinda bad for scripting purpose. Is there any way to overcome this, i.e. directly passing edit 0fbc8ed to the git rebase command?

    Is it idiotic what I’m attempting or is there maybe a clearer, alternative way to do this?

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

    How can I automatically accept what git rebase –interactive presents to me?

  • Git fetch github: Index-pack failed
  • What is the fastest way to clone a git repository over a fast network connection?
  • Extract the tree sha1 from a git commit
  • Use Chef with a non-Git VCS/DVCS
  • Python Parsing subprocess Output
  • Git: How to reset after merging?
  • 2 Solutions collect form web for “Editing old commits non-interactively with git”

    This is a job for “git filter-branch” and the option “–commit-filter”. Look at the manual page here exists a example section.

    You can do the same thing without an interactive rebase:

    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
    
    Git Baby is a git and github fan, let's start git clone.