1

I know how to interactively modify a git history and drop a specific commit but I didn't find a way to do that fully automatically.

I'd like to identify specific commits (e.g. containing a magic string) and have them deleted by a script.

Something like this:

# identify and remove all commits which would be merged to master but should not
for i in $(git --no-pager log --grep='no-push' --pretty=format:"%h" --no-merges HEAD ^master)
do
    echo "Drop commit $i"
    git rebase --drop $i   # <== this is what I want to do
done

Any ideas?

frans
  • 8,868
  • 11
  • 58
  • 132

1 Answers1

0

Taken from here (thanks to jonrsharpe):

# identify and remove all commits which would be merged to master but should not
for i in $(git --no-pager log --grep='no-push' --pretty=format:"%h" --no-merges HEAD ^master)
do
    echo "Drop commit $i"
    git rebase -p --onto $i^ $i
done
frans
  • 8,868
  • 11
  • 58
  • 132
  • totally right and useful - in this case I know I get only git shas without any whitespaces. but feel free to improve the code – frans Mar 04 '20 at 10:14