Restoring deleted files from Git

Cheat-Sheet for restoring deleted files from Git repo #Get a list of deleted files git log --diff-filter=D --summary | grep delete #Show commits where the deleted file was involved, copy latest commit hash to clipboard git log --all -- <PATH_TO_DELETED_FILE> #Restore it into the working copy with: (^ means the commit BEFORE the commit where file was deleted) git checkout <COMMIT-HASH>^ -- <PATH_TO_DELETED_FILE>

February 5, 2022 · 1 min · Jens

Git Rebasing Cheat Sheet

# create branch from develop git pull git checkout -b feature/my-feature # work on branch and commit work. repeat until work is done git commit -am "implement my feature" git push # squash commits with an interactive rebase # first, choose all commits to squash into one git log --oneline # second, squash the last x commits # pick the one to squash into (usually the topmost), squash # the others git rebase -i HEAD~x # forcepush these changes to the remote branch git push --force # refresh work done by others on develop in the meantime... git checkout develop git pull # change back to feature branch and rebase git checkout feature/my-feature git rebase develop # optional: resolve conflicts and then git add . git rebase --continue # since we rewrote history, force push changes to branch git push --force-with-lease # after that, branch can be merged into develop

April 19, 2020 · 1 min · Jens