| Start |
|---|
| Recovering from a lost commit In case you have reverted back to a past commit and lost a newer commit you can recover the lost commit by running Then find your lost commit, and reset back to it by doing |
| Restore a deleted file after a commit In case you have accidentally commited a delete on a file and later realized that you need it back. First find the commit id of the commit that deleted your file. Will give you a sorted summary of commits which deleted files. Then proceed to restore the file by (Replace 81eeccf with your own commit id) |
| Restore file to a previous version To restore a file to a previous version you can use If you have already made local changes to the file (that you do not require!) you can also use the |
| Recover a deleted branch To recover a deleted branch you need to find the commit which was the head of your deleted branch by running You can then recreate the branch by running You will not be able to recover deleted branches if git's garbage collector (opens new window) deleted dangling commits - those without refs. Always have a backup of your repository, especially when you work in a small team / proprietary project |
Recovering from a reset With Git, you can (almost) always turn the clock backDon't be afraid to experiment with commands that rewrite history*. Git doesn't delete your commits for 90 days by default, and during that time you can easily recover them from the reflog:
|
| Recover from git stash To get your most recent stash after running git stash, use To see a list of your stashes, use You will get a list that looks something like this Choose a different git stash to restore with the number that shows up for the stash you want You can also choose 'git stash pop', it works same as 'git stash apply' like.. or Difference in git stash apply and git stash pop... git stash pop:- stash data will be remove from stack of stash list. Ex:- You will get a list that looks something like this Now pop stash data using command Again Check for stash list You will get a list that looks something like this You can see one stash data is removed (popped) from stash list and stash@{1} became stash@{0}. |
Read Article
https://develop.horje.com/learn/1434/reference