Created
November 22, 2019 08:19
-
-
Save saiumesh535/49d60f9593474a5cc96d43155e406264 to your computer and use it in GitHub Desktop.
git commands
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Re-clone | |
GIT=$(git rev-parse --show-toplevel) | |
cd $GIT/.. | |
rm -rf $GIT | |
git clone ... | |
✅ Deletes local, non-pushed commits | |
✅ Reverts changes you made to tracked files | |
✅ Restores tracked files you deleted | |
✅ Deletes files/dirs listed in .gitignore (like build files) | |
✅ Deletes files/dirs that are not tracked and not in .gitignore | |
😀 You won't forget this approach | |
😔 Wastes bandwidth | |
Following are other commands I forget daily. | |
Clean and reset | |
git clean --force -d -x | |
git reset --hard | |
❌ Deletes local, non-pushed commits | |
✅ Reverts changes you made to tracked files | |
✅ Restores tracked files you deleted | |
✅ Deletes files/dirs listed in .gitignore (like build files) | |
✅ Deletes files/dirs that are not tracked and not in .gitignore | |
Clean | |
git clean --force -d -x | |
❌ Deletes local, non-pushed commits | |
❌ Reverts changes you made to tracked files | |
❌ Restores tracked files you deleted | |
✅ Deletes files/dirs listed in .gitignore (like build files) | |
✅ Deletes files/dirs that are not tracked and not in .gitignore | |
Reset | |
git reset --hard | |
❌ Deletes local, non-pushed commits | |
✅ Reverts changes you made to tracked files | |
✅ Restores tracked files you deleted | |
❌ Deletes files/dirs listed in .gitignore (like build files) | |
❌ Deletes files/dirs that are not tracked and not in .gitignore | |
Notes | |
Test case for confirming all the above (use bash or sh): | |
mkdir project | |
cd project | |
git init | |
echo '*.built' > .gitignore | |
echo 'CODE' > a.sourceCode | |
mkdir b | |
echo 'CODE' > b/b.sourceCode | |
cp -r b c | |
git add . | |
git commit -m 'Initial checkin' | |
echo 'NEW FEATURE' >> a.sourceCode | |
cp a.sourceCode a.built | |
rm -rf c | |
echo 'CODE' > 'd.sourceCode' | |
See also | |
git revert to make new commits that undo prior commits | |
git checkout to go back in time to prior commits (may require running above commands first) | |
git stash same as git reset above, but you can undo it |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment