Skip to content

Instantly share code, notes, and snippets.

@chmouel
Last active September 30, 2021 07:43
Show Gist options
  • Save chmouel/9740643 to your computer and use it in GitHub Desktop.
Save chmouel/9740643 to your computer and use it in GitHub Desktop.
If you have a gerrit review that follow-up another review and if the review A had rebased you end up in a outdated branch, this script takes an argument the parent branch and rebase the current patch against it.
#!/bin/bash
# -*- coding: utf-8 -*-
# Author: Chmouel Boudjnah <[email protected]>
#
# 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.
set -ex
BRANCHTO=$1
if [[ -z ${BRANCHTO} ]];then
echo "You need to specify a parent branch as the argument of this script"
exit 1
fi
LAST_COMMIT=$(git rev-parse HEAD)
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
TEMP_BRANCH=${CURRENT_BRANCH}-$$
git checkout -b ${TEMP_BRANCH} ${BRANCHTO}
git cherry-pick ${LAST_COMMIT}
git branch -D ${CURRENT_BRANCH}
git branch -M ${TEMP_BRANCH} ${CURRENT_BRANCH}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment