(window.webpackJsonp=window.webpackJsonp||[]).push([[1144],{1552:function(t,e,a){"use strict";a.r(e);var s=a(31),r=Object(s.a)({},(function(){var t=this,e=t.$createElement,a=t._self._c||e;return a("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[a("h1",{attrs:{id:"recovering"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#recovering"}},[t._v("#")]),t._v(" Recovering")]),t._v(" "),a("h2",{attrs:{id:"recovering-from-a-lost-commit"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#recovering-from-a-lost-commit"}},[t._v("#")]),t._v(" Recovering from a lost commit")]),t._v(" "),a("p",[t._v("In case you have reverted back to a past commit and lost a newer commit you can recover the lost commit by running")]),t._v(" "),a("div",{staticClass:"language-git extra-class"},[a("pre",{pre:!0,attrs:{class:"language-git"}},[a("code",[t._v("git reflog\n\n")])])]),a("p",[t._v("Then find your lost commit, and reset back to it by doing")]),t._v(" "),a("div",{staticClass:"language-git extra-class"},[a("pre",{pre:!0,attrs:{class:"language-git"}},[a("code",[t._v("git reset HEAD --hard \n\n")])])]),a("h2",{attrs:{id:"restore-a-deleted-file-after-a-commit"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#restore-a-deleted-file-after-a-commit"}},[t._v("#")]),t._v(" Restore a deleted file after a commit")]),t._v(" "),a("p",[t._v("In case you have accidentally commited a delete on a file and later realized that you need it back.")]),t._v(" "),a("p",[t._v("First find the commit id of the commit that deleted your file.")]),t._v(" "),a("div",{staticClass:"language-git extra-class"},[a("pre",{pre:!0,attrs:{class:"language-git"}},[a("code",[t._v("git log --diff-filter=D --summary\n\n")])])]),a("p",[t._v("Will give you a sorted summary of commits which deleted files.")]),t._v(" "),a("p",[t._v("Then proceed to restore the file by")]),t._v(" "),a("div",{staticClass:"language-git extra-class"},[a("pre",{pre:!0,attrs:{class:"language-git"}},[a("code",[t._v("git checkout 81eeccf~1 \n\n")])])]),a("p",[t._v("(Replace 81eeccf with your own commit id)")]),t._v(" "),a("h2",{attrs:{id:"restore-file-to-a-previous-version"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#restore-file-to-a-previous-version"}},[t._v("#")]),t._v(" Restore file to a previous version")]),t._v(" "),a("p",[t._v("To restore a file to a previous version you can use "),a("code",[t._v("reset")]),t._v(".")]),t._v(" "),a("div",{staticClass:"language-git extra-class"},[a("pre",{pre:!0,attrs:{class:"language-git"}},[a("code",[t._v("git reset \n\n")])])]),a("p",[t._v("If you have already made local changes to the file (that you do not require!) you can also use the "),a("code",[t._v("--hard")]),t._v(" option")]),t._v(" "),a("h2",{attrs:{id:"recover-a-deleted-branch"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#recover-a-deleted-branch"}},[t._v("#")]),t._v(" Recover a deleted branch")]),t._v(" "),a("p",[t._v("To recover a deleted branch you need to find the commit which was the head of your deleted branch by running")]),t._v(" "),a("div",{staticClass:"language-git extra-class"},[a("pre",{pre:!0,attrs:{class:"language-git"}},[a("code",[t._v("git reflog\n\n")])])]),a("p",[t._v("You can then recreate the branch by running")]),t._v(" "),a("div",{staticClass:"language-git extra-class"},[a("pre",{pre:!0,attrs:{class:"language-git"}},[a("code",[t._v("git checkout -b \n\n")])])]),a("p",[t._v("You will not be able to recover deleted branches if git's "),a("a",{attrs:{href:"https://git-scm.com/docs/git-gc",target:"_blank",rel:"noopener noreferrer"}},[t._v("garbage collector"),a("OutboundLink")],1),t._v(" deleted dangling commits - those without refs. Always have a backup of your repository, especially when you work in a small team / proprietary project")]),t._v(" "),a("h2",{attrs:{id:"recovering-from-a-reset"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#recovering-from-a-reset"}},[t._v("#")]),t._v(" Recovering from a reset")]),t._v(" "),a("h3",{attrs:{id:"with-git-you-can-almost-always-turn-the-clock-back"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#with-git-you-can-almost-always-turn-the-clock-back"}},[t._v("#")]),t._v(" With Git, you can (almost) always turn the clock back")]),t._v(" "),a("p",[t._v("Don'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:")]),t._v(" "),a("div",{staticClass:"language-git extra-class"},[a("pre",{pre:!0,attrs:{class:"language-git"}},[a("code",[a("span",{pre:!0,attrs:{class:"token command"}},[t._v("$ git reset @~3 # go back 3 commits")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token command"}},[t._v("$ git reflog")]),t._v("\nc4f708b HEAD@{0}: reset: moving to @~3\n2c52489 HEAD@{1}: commit: more changes\n4a5246d HEAD@{2}: commit: make important changes\ne8571e4 HEAD@{3}: commit: make some changes\n... earlier commits ...\n"),a("span",{pre:!0,attrs:{class:"token command"}},[t._v("$ git reset 2c52489")]),t._v("\n... and you're back where you started\n\n")])])]),a("ul",[a("li",[a("strong",[t._v("Watch out for options like "),a("code",[t._v("--hard")]),t._v(" and "),a("code",[t._v("--force")]),t._v(" though — they can discard data.")]),a("br")]),t._v(" "),a("li",[a("strong",[t._v("Also, avoid rewriting history on any branches you're collaborating on.")])])]),t._v(" "),a("h2",{attrs:{id:"recover-from-git-stash"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#recover-from-git-stash"}},[t._v("#")]),t._v(" Recover from git stash")]),t._v(" "),a("p",[t._v("To get your most recent stash after running git stash, use")]),t._v(" "),a("div",{staticClass:"language-git extra-class"},[a("pre",{pre:!0,attrs:{class:"language-git"}},[a("code",[t._v("git stash apply\n\n")])])]),a("p",[t._v("To see a list of your stashes, use")]),t._v(" "),a("div",{staticClass:"language-git extra-class"},[a("pre",{pre:!0,attrs:{class:"language-git"}},[a("code",[t._v("git stash list\n\n")])])]),a("p",[t._v("You will get a list that looks something like this")]),t._v(" "),a("div",{staticClass:"language-git extra-class"},[a("pre",{pre:!0,attrs:{class:"language-git"}},[a("code",[t._v("stash@{0}: WIP on master: 67a4e01 Merge tests into develop\nstash@{1}: WIP on master: 70f0d95 Add user role to localStorage on user login\n\n")])])]),a("p",[t._v("Choose a different git stash to restore with the number that shows up for the stash you want")]),t._v(" "),a("div",{staticClass:"language-git extra-class"},[a("pre",{pre:!0,attrs:{class:"language-git"}},[a("code",[t._v("git stash apply stash@{2}\n\n")])])]),a("p",[t._v("You can also choose 'git stash pop', it works same as 'git stash apply' like..")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("\ngit stash pop \n\n")])])]),a("p",[t._v("or")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("\ngit stash pop stash@{2}\n\n")])])]),a("p",[t._v("Difference in git stash apply and git stash pop...")]),t._v(" "),a("p",[a("strong",[t._v("git stash pop")]),t._v(":- stash data will be remove from stack of stash list.")]),t._v(" "),a("p",[t._v("Ex:-")]),t._v(" "),a("div",{staticClass:"language-git extra-class"},[a("pre",{pre:!0,attrs:{class:"language-git"}},[a("code",[t._v("git stash list\n\n")])])]),a("p",[t._v("You will get a list that looks something like this")]),t._v(" "),a("div",{staticClass:"language-git extra-class"},[a("pre",{pre:!0,attrs:{class:"language-git"}},[a("code",[t._v("stash@{0}: WIP on master: 67a4e01 Merge tests into develop\nstash@{1}: WIP on master: 70f0d95 Add user role to localStorage on user login\n\n")])])]),a("p",[t._v("Now pop stash data using command")]),t._v(" "),a("div",{staticClass:"language-git extra-class"},[a("pre",{pre:!0,attrs:{class:"language-git"}},[a("code",[t._v("git stash pop\n\n")])])]),a("p",[t._v("Again Check for stash list")]),t._v(" "),a("div",{staticClass:"language-git extra-class"},[a("pre",{pre:!0,attrs:{class:"language-git"}},[a("code",[t._v("git stash list\n\n")])])]),a("p",[t._v("You will get a list that looks something like this")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("\nstash@{0}: WIP on master: 70f0d95 Add user role to localStorage on user login\n\n")])])]),a("p",[t._v("You can see one stash data is removed (popped) from stash list and stash@{1} became stash@{0}.")])])}),[],!1,null,null,null);e.default=r.exports}}]);