Git useful commands

Published: Fri 28 April 2023
Updated: Fri 03 May 2024

Delete submodule

ref: https://gist.github.com/myusuf3/7f645819ded92bda6677?permalink_comment_id=3915500#gistcomment-3915500

# Remove the submodule entry from .git/config
git submodule deinit -f path/to/submodule

# Remove the submodule directory from the superproject's .git/modules directory
rm -rf .git/modules/path/to/submodule

# Remove the entry in .gitmodules and remove the submodule directory located at path/to/submodule
git rm -f path/to/submodule

Modify a commit (not last one)

ref: https://stackoverflow.com/questions/1186535/how-do-i-modify-a-specific-commit

git rebase --interactive bbc643cd~
# in vim, modify this commit to edit
git commit --all --amend --no-edit
git rebase --continue

LFS

Git LFS enables clone to fetch large files associated with a specific commit, rather than it's full history. One needs to install git-lfs first:

apt-get install git-lfs

ref: https://zzz.buzz/zh/2016/04/19/the-guide-to-git-lfs (Chinese)

links