no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
— | blog:2019:0102_recovering_deleted_git_branch [2020/07/10 12:11] (current) – created - external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Recovering deleted GIT branch ====== | ||
+ | |||
+ | {{tag> | ||
+ | |||
+ | Today I'm back at work, so as a regular routine, I'm cleaned my list of " | ||
+ | |||
+ | ====== ====== | ||
+ | |||
+ | Was I really frightened when I realized that I had just deleted a branch containing some work that was not merged yet on our master branch... If there is something I really hate, it is to **delete information**, | ||
+ | |||
+ | So, I started to look for a way to fix that hoping that git would be smart enough to be able to handle such stupid mistakes, and indeed it is! I found a few links with indications on how to proceed, such as: | ||
+ | |||
+ | * https:// | ||
+ | * https:// | ||
+ | |||
+ | And this is worth mentioning here, just in case this could help someone else: | ||
+ | |||
+ | Let's assume you just deleted your branch **" | ||
+ | git branch -D " | ||
+ | |||
+ | Then you cry... because you just lost hours of work... But fear not my child, you can still be saved! :-) | ||
+ | |||
+ | => The first think you need to do is to retrieve the **sha** of the last commit you did on that branch you just removed. To do this, we use the git **reflog** command. For instance in my case, I had removed a branch called **issue665_rcs_random_commands**, | ||
+ | a64869a HEAD@{0}: pull: Fast-forward | ||
+ | 8346ad0 HEAD@{1}: pull: Fast-forward | ||
+ | 7ab3da1 HEAD@{2}: checkout: moving from issue665_rcs_random_commands to master | ||
+ | 703f3fe HEAD@{3}: commit: Issue #665: Fixing AVT callbacks execution in main thread. | ||
+ | f52d0d1 HEAD@{4}: commit: Issue #665: preventing AVT leave acquisition lock without valid input stream. | ||
+ | a650707 HEAD@{5}: commit: Issue #665: Fixing unit tests.</ | ||
+ | |||
+ | From that output, I could see that the last commit I did on that branch for my "issue #665" had an sha value of **703f3fe**. | ||
+ | |||
+ | => Then you can restore the branch with the following command: <sxh bash>git branch my_feature_branch 703f3fe</ | ||
+ | |||
+ | < | ||
+ | |||
+ | And then, bingo! You should have your branch name back into your local branch list. And you can get back on it with the usual command: <sxh bash>git checkout my_feature_branch</ | ||
+ | |||
+ | That's it! Those few commands saved my day already. They might save yours too. | ||