Git
Topics: Version control system
Git is a distributed version control system for tracking changes to files and collaborating on software projects.
Subtopics
Reset a submodule
git submodule update --init
Split a commit
In order to split commit 123abc, run git rebase -i 123abc~, choose edit and exit.
Then git reset HEAD~ to dissolve the commit. Now commit the changes as you want to.
Finally, git rebase --continue.
Show file in a different branch
git show <branch>:<file>
To copy a file from a different branch, use:
git checkout <branch> -- <file>
Erase a secrets file
Use the filter-repo Python script to filter out a specific path:
git filter-repo --path ... --inverse-paths
Search commits
git log --all --grep='New feature'
Check out a specific ref on a branch
git checkout -B <branch> <commit/tag/etc>
Unlike a detached HEAD checkout, this still lets you do git pull or equivalents to later bring yourself up to the head of the branch (and you can diff between it and the upstream head and etc etc). It’s especially handy for projects that tag releases on their main branch.
Switching from “master” to “main”
Create main branch:
git branch -m master main
git push -u origin main
Then make main the default branch on Gitlab, Heroku etc. and delete the master branch.
Configure git to always create repositories with main:
git config --global init.defaultBranch main
Script to safely hard reset
https://gist.github.com/chx/85db0ebed1e02ab14b1a65b6024dea29
Bookmarks
- Git - Book
- Easily rename your Git default branch from master to main
- Conventional Commits
- Git sizer
- Oh Shit, Git!?!