Some ways to recover code on Git
Git is a powerful tool for project management, most commonly used today. In some cases you need to recover the code, sleep code, blame. You will often encounter some of the following.
1. Just finished editing the code, haven't added it
1 2 | $ git clean -df $ git checkout -. |
2. Missed add hand but not committed
1 2 | $ git reset HEAD $ git clean -df |
3. Commit, but haven't pushed yet
1 | $ git reset HEAD ~ 1 --hard |
4. Commit, please push
Push it up, which means that there might be someone fetching to use, but people have already taken it, there is no recoil. In this case, you need to correct it: "Ah, I was wrong, get this."
Therefore, we push another commit, the content is the opposite of the one that was pushed to correct.
1 | $ git revert HEAD ~ 1..HEAD |
Conclusion
Git is a very powerful tool to control your source code.
The article is posted on your Blog ( Git – Restoring old full code ).
Glad to receive comments from everyone :))