Git Cheatsheet
Git CheatSheet.
Log
git log --oneline
Shallow Clone
Avoid getting entire history of a large repo when you only need the latest commit.
git clone --depth 1 [email protected]:aws/aws-sdk-go.git
Revert
git revert abcd
Cherry Pick
# Pick multiple commits to squash
# -n means do not commit
git cherry-pick -n commit1
git cherry-pick -n commit2
git commit
Diff
Generate diff of two branches and apply it to another branch to avoid cherry-picking many commits.
git checkout feature
git diff main > /tmp/feature.patch
git checkout -b feature-v2
git apply /tmp/feature.patch
LFS
Download the lfs binary from https://git-lfs.com/ and run the following to setup the lfs for your account. You don't need to run it for every repository.
git lfs install
For each repository, run git lfs track "*.ext"
to track the large files.
# Photoshop files
git lfs track "*.psd"
The command actually updates .gitattributes
file. Which you can edit directly in editor.
*.psd filter=lfs diff=lfs merge=lfs -text