Last active
May 6, 2019 10:16
-
-
Save msohn/b0c139e60d8da3e5df2cb9c9c7191945 to your computer and use it in GitHub Desktop.
Revert a git commit appending the original commit message\
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Copyright (C) 2019 Matthias Sohn | |
# | |
# Licensed under the Apache License, Version 2.0 (the "License"); | |
# you may not use this file except in compliance with the License. | |
# You may obtain a copy of the License at | |
# | |
# http://www.apache.org/licenses/LICENSE-2.0 | |
# | |
# Unless required by applicable law or agreed to in writing, software | |
# distributed under the License is distributed on an "AS IS" BASIS, | |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
# See the License for the specific language governing permissions and | |
# limitations under the License. | |
read -r -d '' documentation <<-"EOT" | |
usage: git-custom-revert <commit> | |
<commit> Commit to revert. | |
Reverts the given commit appending the original commit message to the revert commit message. | |
EOT | |
let $# || (echo "$documentation" && exit) | |
commit=$(git rev-parse $1) | |
oldmsg=$(git log --format=%B -n 1 "$commit") | |
git revert --no-commit "$commit" \ | |
&& git commit --no-edit | |
revertmsg=$(git log --format=%B -n1) | |
revertmsg+=$'\n'"Original commit message:" | |
git commit --amend -m "$revertmsg" -m "$oldmsg" > /dev/null 2>&1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello Matthias, Nilay from our company had asked about this, and you replied with this. Just looking at it this, and want to check.. is this a custom hook that we can set in the project's hooks dir, or something else?