Skip to content

Instantly share code, notes, and snippets.

@esebastian
Last active May 18, 2022 13:14
Show Gist options
  • Save esebastian/db27fbbef193c75679e5 to your computer and use it in GitHub Desktop.
Save esebastian/db27fbbef193c75679e5 to your computer and use it in GitHub Desktop.

Revisions

  1. esebastian revised this gist Jul 5, 2014. 1 changed file with 7 additions and 7 deletions.
    14 changes: 7 additions & 7 deletions git-amend
    Original file line number Diff line number Diff line change
    @@ -1,12 +1,12 @@
    #!/bin/sh
    # Amend one specific commit and rebase to apply the changes
    # Given the SHA hash or a reference of the commit to amend,
    # it checkouts the commit, amends it interactively and
    # rebases the repo history in master.
    # Amend the commit message one specific commit and rebase
    # to apply the changes. Given the SHA hash or a reference
    # of the commit to amend, it checkouts the commit, amends
    # it interactively and rebases the repo history in master.
    #
    # This action is destructive to your repo's history and this should not
    # be performed on a repo that has been shared with others, because it
    # will force them to reset their history.
    # This action is destructive to your repo's history and this
    # should not be performed on a repo that has been shared with
    # others, because it will force them to reset their history.
    #
    # Use at your own risk.
    #
  2. esebastian revised this gist Jul 5, 2014. 1 changed file with 10 additions and 1 deletion.
    11 changes: 10 additions & 1 deletion git-amend
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,16 @@
    # Amend one specific commit and rebase to apply the changes
    # Given the SHA hash or a reference of the commit to amend,
    # it checkouts the commit, amends it interactively and
    # rebases the repo history in master
    # rebases the repo history in master.
    #
    # This action is destructive to your repo's history and this should not
    # be performed on a repo that has been shared with others, because it
    # will force them to reset their history.
    #
    # Use at your own risk.
    #
    # Put the script in your path and invoke it this way:
    # git amend <SHA>

    if [[ ! -n $1 ]]; then
    echo "usage: git amend <SHA>\n"
  3. esebastian revised this gist Jul 5, 2014. 1 changed file with 4 additions and 3 deletions.
    7 changes: 4 additions & 3 deletions git-amend
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,8 @@
    !/bin/sh
    #!/bin/sh
    # Amend one specific commit and rebase to apply the changes
    # Given the SHA hash of the commit to amend, it checkouts the commit,
    # amends it interactively and rebases the repo history
    # Given the SHA hash or a reference of the commit to amend,
    # it checkouts the commit, amends it interactively and
    # rebases the repo history in master

    if [[ ! -n $1 ]]; then
    echo "usage: git amend <SHA>\n"
  4. esebastian created this gist Jul 5, 2014.
    16 changes: 16 additions & 0 deletions git-amend
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    !/bin/sh
    # Amend one specific commit and rebase to apply the changes
    # Given the SHA hash of the commit to amend, it checkouts the commit,
    # amends it interactively and rebases the repo history

    if [[ ! -n $1 ]]; then
    echo "usage: git amend <SHA>\n"
    exit 1
    fi

    echo "Amending $1..."

    git checkout $1 && git commit --amend && git rebase HEAD master

    [[ $? -eq 0 ]] && echo Done!
    [[ $? -ne 0 ]] && echo Error!