Git Tips - stereoboy/Study GitHub Wiki

Tips

Splitting a subfolder out into a new repository

sudo apt-get install git-filter-repo

git filter-repo --subdirectory-filter FOLDER-NAME
# Filter the specific branch by using a single sub-directory as the root for the new repository

Follow history of renamed files

git log --follow -p // follow history of renamed files

tig for cli gui

sudo apt-get install -y tig
tig --follow -p

How To: Merge a Git submodule into its main repository

1. git remote add -f Bproject /path/to/B
2. git merge -s ours --no-commit --allow-unrelated-histories Bproject/master
3. git read-tree --prefix=dir-B/ -u Bproject/master
4. git commit -m "Merge B project as our subdirectory"

5. git pull -s subtree Bproject master


1. name the other project "Bproject", and fetch.
2. prepare for the later step to record the result as a merge.
3. read "master" branch of Bproject to the subdirectory "dir-B".
4. record the merge result.

5. pull in subsequent update from Bproject using "subtree" merge

Print Version Info

$ git describe --tags
v0.3.1-2-g07736b5

$ git rev-parse --short HEAD
07736b5

$ git rev-parse --abbrev-ref HEAD
main

git describe

$ git tag -n
docker-v0.0.3   update: update comments in nesfr_vr_remote_tunnel.service
docker-v0.0.4   docker-v0.0.4
docker-v0.1.0   update: remove acpid-poweroff
v0.0.0          initial version
v0.1.0          update: update scripts for debian packaging
v0.3.0          update: subscribe current pose from rover
$ git describe --tags
docker-v0.1.0-5-g7668341   // <- latest tag
$ git describe 
docker-v0.0.4-15-g7668341 // <- annotated tag
$ git describe --tags --match="v*"
v0.3.0-6-g7668341    // <- matching pattern
$ git describe --all --tags --match="v*"
tags/v0.3.0-6-g7668341