diff options
author | Robin Haberkorn <rhaberkorn@fmsbw.de> | 2025-10-06 00:48:48 +0300 |
---|---|---|
committer | Robin Haberkorn <rhaberkorn@fmsbw.de> | 2025-10-06 00:48:48 +0300 |
commit | ad9e7cd5117c965222aae708f660e56d537914fc (patch) | |
tree | 580006656ec76513500170e5646e92e7819c6c0b /git | |
download | snippets-ad9e7cd5117c965222aae708f660e56d537914fc.tar.gz |
imported all of my Github gists from https://gist.github.com/rhaberkorn
Diffstat (limited to 'git')
-rwxr-xr-x | git/git-checkout-clean.sh | 19 | ||||
-rwxr-xr-x | git/git-fixup.sh | 12 | ||||
-rwxr-xr-x | git/git-move-tag.sh | 11 | ||||
-rwxr-xr-x | git/git-rename-tag.sh | 12 |
4 files changed, 54 insertions, 0 deletions
diff --git a/git/git-checkout-clean.sh b/git/git-checkout-clean.sh new file mode 100755 index 0000000..927b6f8 --- /dev/null +++ b/git/git-checkout-clean.sh @@ -0,0 +1,19 @@ +#!/bin/sh +# This script performs a checkout with same arguments as `git checkout` +# but makes sure that submodules are initialized in exactly the way +# described in the branch/tag. +# This is useful to avoid having to cleanup the tree after checkout +# to prevent files interfering with Eclispe and updating submodules +# manually. +# +# NOTE: This does not prevent other untracked files from intefering +# with Eclipse. +# +# WARNING: THIS WILL DISCARD ALL LOCAL MODIFICATIONS TO YOUR SUBMODULES. +# MAKE SURE TO COMMIT/PUSH OR SAVE THEM BEFORE YOU EXECUTE THIS SCRIPT. +set -e + +git submodule foreach 'rm -rf $toplevel/$path' +git checkout "$@" +git submodule sync +git submodule update --init diff --git a/git/git-fixup.sh b/git/git-fixup.sh new file mode 100755 index 0000000..9dfc2ee --- /dev/null +++ b/git/git-fixup.sh @@ -0,0 +1,12 @@ +#!/bin/sh +# Creates a commit from the given files and automatically +# squashes it into the last commit on HEAD. +set -e + +if [ "x`git branch -r --contains HEAD`" != x ]; then + echo "HEAD commit already pushed?" + exit 1 +fi + +git commit --fixup=HEAD "$@" +git rebase --autostash --autosquash HEAD~~ diff --git a/git/git-move-tag.sh b/git/git-move-tag.sh new file mode 100755 index 0000000..05e82be --- /dev/null +++ b/git/git-move-tag.sh @@ -0,0 +1,11 @@ +#!/bin/sh +# git-move-tag <tag-name> <target> + +tagName=$1 +# Support passing branch/tag names (not just full commit hashes) +newTarget=$(git rev-parse $2^{commit}) + +git cat-file -p refs/tags/$tagName | +sed "1 s/^object .*$/object $newTarget/g" | +git hash-object -w --stdin -t tag | +xargs -I {} git update-ref refs/tags/$tagName {} diff --git a/git/git-rename-tag.sh b/git/git-rename-tag.sh new file mode 100755 index 0000000..282a7ea --- /dev/null +++ b/git/git-rename-tag.sh @@ -0,0 +1,12 @@ +#!/bin/sh +# git-rename-tag <old-name> <new-name> +# NOTE: This works on the "origin" remote and preserves +# annotations. +set -e + +# Creates a new tag on the remote AND removes the old tag +git push origin refs/tags/$1:refs/tags/$2 :refs/tags/$1 +# Remove the old local tag +git tag -d $1 +# Fetch the new tag +git fetch origin refs/tags/$2:refs/tags/$2 |