Skip to content

Instantly share code, notes, and snippets.

@lee-pai-long
Created September 25, 2019 12:32
Show Gist options
  • Save lee-pai-long/6c53a476a8bf0ab7f675a8abf29074d9 to your computer and use it in GitHub Desktop.
Save lee-pai-long/6c53a476a8bf0ab7f675a8abf29074d9 to your computer and use it in GitHub Desktop.

GIT: Keep branch author on squash merge

When merging topic branches with the squash method, i.e: git merge --squash ${topic_branch}, by default the author and committer of the merge commit following will be the one executing the merge.

But most of the time this person(or tool) is the integrator and to be able to follow back a topic author we need to force the author of the commit.

git commit --author="$( \
    cat .git/SQUASH_MSG \
    | grep -m1 '^commit' \
    | awk '{print $2}' \
    | xargs git log -1 --pretty=format:'%an <%ae>' \
)"

The main caveat is that tt takes the author of the last commit of the branch, so it will not work well on shared topic branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment