# git ### Sparse checkouts Useful when you only need a few files checked out in large repos ```javascript git clone -n --depth=1 --filter=tree:0 git@github.com:giantswarm/control-plane-catalog.git # add the directories you want to work in git sparse-checkout set --no-cone . oauth2-proxy-3.2.0.tgz-meta/ # checkout the files git checkout -- oauth2-proxy-3.2.0.tgz-meta/ # make changes, then stage them git add --sparse oauth2-proxy-3.2.0.tgz-meta/ ``` *** ### Search git history for a [string](stringhttps://stackoverflow.com/questions/4468361/search-all-of-git-history-for-a-string)) * [https://stackoverflow.com/questions/4468361/search-all-of-git-history-for-a-string](stringhttps://stackoverflow.com/questions/4468361/search-all-of-git-history-for-a-string)) ```javascript git log -S ``` *** ### Move commits from main to feature branch ``` git checkout main git checkout git checkout -b feature_branch git rebase main # or git cherry-pick git checkout main git reset --hard ``` --- ### Partially revert previous commit * Revert the commit without committing the change: ```javascript git revert -n ``` * Edit the files to retain the changes manually, or select the hunks: ```javascript git add -p filename.ext ```