Vikas Rajput
Vikas Rajput

@vikasrajputin

9 تغريدة 9 قراءة Sep 16, 2022
Next time when you screw up something
Remember these 5 Git Commands to save you hours of troubleshooting
🧵👇
1. Revert commit (before push):
- To only undo the last commit command but keep the work
git reset --soft HEAD~1
- Or, revert your work and undo the last commit as well
git reset --hard HEAD~1
2. Revert commit (after push):
- To undo the last commit which is already pushed on the remote branch
git revert HEAD~1
- To undo any commit pass the commit hash id
git revert <commit-hash-id>
3. Stash a specific file
- To only stash a selected file
git stash push -m "stash-message" <file-path>
- "-m stash-message" is optional in the above command, it stands for
message and adds more description to your stash
4. Split recent commit (or any commit)
- If by mistake you added all files in a single commit and want to split into multiple commits then use:
git rebase HEAD~
- Now, as usual, choose each file and commit them individually
5. Recover lost files
- To recover any accidentally deleted files
git restore -- <file-path>
- This will also get you those files which are even removed from recycle bin
6. By mistake committed on wrong branch
- Suppose you committed last two commits in "master" instead of "feature" branch
- Perform the following series of commands (currently you're on master)
git reset HEAD~2
git stash
git checkout feature
git stash pop
Thanks for staying till the end!
Before you go, do you know?
I've also started writing on LinkedIn.
I share some exclusive content there, which I never share here.
Follow me on Linkedin to stay updated with Backend content:
linkedin.com
Namaste, I'm Vikas!
Every Mon, Wed & Friday - I tweet a thread on Backend Development.
Follow me @vikasrajputin to read all my future threads.
Like and RT the first tweet below to support my work.

جاري تحميل الاقتراحات...