Interactive Rebase
Use interactive rebasing
- use when ready to merge a feature branch into dev or master
- don’t use interactive rebase on commits that you’ve already pushed to remote branch
- use to clean local commit before merging into shared branch
git rebase -i HEAD~3 // this will go down 3
// squashing 2 commits together
git rebase -i HEAD~4
// when popup opens
pick .....
squash ebjdifjd
Cherry-Picking
Use Cherry-pick when you’ve commited to the wrong branch
- checkout to the suppose branch the commit is supposed to land on.
git cherry-pick 8704d0f
to add the commit to the branch- then git reset hard on the branch which doesn’t need to have that commit
Reflog
git reflog
if you’ve deleted some commits that contains key information, you can use reflog to get the commit hash and restore those commit’s on another branch git branch new-code 9479fbe
You can also use reflog to restore deleted branches
- git reflog
- then copy the hashcode and
git branch feature/login 3099dfd
Submodules
Used to seperate library files or vendor files from your project. The files are downloaded on your local to work with, but are not part of your parent remote project.
- create a vendor / module / lib folder to host those files and cd into that folder
- add a submodule by
git submodule add remoteurl of that repo
Installing modules from a cloned repo
- Clone the repo
- Initialize the submodules
git submodule update --init --recursive
- or we can clone directory with installing modules by doing
git clone --recursive-submodules https://github.com/apache/whatever
- submodules is checkout from a specific commit, revision but not from a branch
Search & Find in git
By Date --before/ --after
git log --after="2021-7-1"
git log --after="2021-7-1" --before="2021-7-5"
By Message --grep
git log --grep="refactor"
By Author --author
git log --author="kofi ramos"
By File --<filename>
git log -- Readme.md
By Branch <branch-A>
git log feature/login..main