Skip to content

Instantly share code, notes, and snippets.

@vkareh
Created July 19, 2019 12:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vkareh/d96e28b46eafe153bd33049b836a4c6e to your computer and use it in GitHub Desktop.
Save vkareh/d96e28b46eafe153bd33049b836a4c6e to your computer and use it in GitHub Desktop.
[color]
ui = true
[push]
default = simple
[core]
editor = vim
excludesfile = ~/.gitignore
autocrlf = input
[grep]
lineNumber = true
[diff]
tool = meld
[merge]
tool = meld
[alias]
st = status -uno
dif = diff
tree = log --pretty=oneline --abbrev-commit --graph --decorate
hist = log --pretty=format:'%h %ad | %s%d [%an]' --graph --date=short
sync = !git checkout master && git fetch upstream && git pull upstream master && git push
backport-file = "!f(){ for f in $(git diff --name-only --diff-filter=A ${1}^1..${1}); do git cat-file -p $(git ls-tree ${1} ${f} | awk '{print $3}') > ${f}; git add ${f}; done; }; f"
backport-url = "!f() { echo '\nupstream commit:'; git remote -v | awk '{print $2}' | sed -e 's|:|/|' | sed -e 's|git@|https://|' | sed -e 's|.git$|/commit/|' | uniq; git rev-parse --short ${1}; }; f"
backport = "!f(){ git backport-file ${1} ; git difftool -d ${1}^1..${1} & git difftool -d ${1} -- $(git diff --name-only ${1}^1..${1}); git log ${1}^1..${1} | tail --lines=+5 | sed -e 's|^ ||'; git backport-url ${1}; }; f"
@vkareh
Copy link
Author

vkareh commented Jul 19, 2019

To use the backport commit (using caja as an example)

$ git clone git@github.com:mate-desktop/caja.git
$ cd caja
$ git remote add nautilus git@gitlab.gnome.org:GNOME/nautilus.git
$ git fetch nautilus

Now the upstream project is set up as a remote in the downstream. Then:

$ git backport <commit hash from nautilus>

This will open two instances of meld: one with the change within nautilus, as reference, and one instance from nautilus to caja. Think of it as a poor-man's three-way diff. Once the right lines are moved from nautilus to caja, close meld and this will show up in terminal:

$ ...
foo bar commit title

commit description blah blah

upstream commit:
https://gitlab.gnome.org/GNOME/nautilus/commit/
https://github.com/mate-desktop/caja/commit/
2ac89eff

So you copy that thing and run git commit -a and paste that, removing the caja line to append the hash to the nautilus URL, ending with the following commit message:

foo bar commit title

commit description blah blah

upstream commit:
https://gitlab.gnome.org/GNOME/nautilus/commit/2ac89eff

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