Recover a git repo which was overwritten with an older version
Clash Royale CLAN TAG#URR8PPP
up vote
2
down vote
favorite
I've just run tar x
by mistake instead of tar c
, and overwrote my git repo with a few days older version. This will have left alone any files I had newly created though, including objects in .git
. How can I recover as much as possible?
git data-recovery
add a comment |Â
up vote
2
down vote
favorite
I've just run tar x
by mistake instead of tar c
, and overwrote my git repo with a few days older version. This will have left alone any files I had newly created though, including objects in .git
. How can I recover as much as possible?
git data-recovery
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I've just run tar x
by mistake instead of tar c
, and overwrote my git repo with a few days older version. This will have left alone any files I had newly created though, including objects in .git
. How can I recover as much as possible?
git data-recovery
I've just run tar x
by mistake instead of tar c
, and overwrote my git repo with a few days older version. This will have left alone any files I had newly created though, including objects in .git
. How can I recover as much as possible?
git data-recovery
edited Nov 10 '17 at 15:00
asked Nov 10 '17 at 14:19
sourcejedi
19.5k32681
19.5k32681
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
2
down vote
accepted
Make a copy of the whole mess first, just in case.
git fsck
will show dangling objects and commits. Find the newest dangling commit. I fed all the commit hashes to gitk
, and it just shows the most "recent" one at the top. As well as only having a few commits to deal with, I only had a single branch to recover - this would be more complex if there was more than one head.
Then git stash
to stash currently uncommitted changes for inspection.
I was then able to git reset --hard
to the commit hash determined above.
git stash pop
also merged back pretty cleanly. I think I got pretty much everything I wanted back again.
If you didn't do anything "clever" between the backup point and the restore point all commits should be already there, you might be able to get away with just moving HEAD. You'll lose some of the changes not already committed though.
â Satà  Katsura
Nov 10 '17 at 14:29
That's what I did with thegit reset --hard HASH
command. The real trick is the bit before that, finding the hash of the commit you want to move to.
â sourcejedi
Nov 10 '17 at 14:58
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
Make a copy of the whole mess first, just in case.
git fsck
will show dangling objects and commits. Find the newest dangling commit. I fed all the commit hashes to gitk
, and it just shows the most "recent" one at the top. As well as only having a few commits to deal with, I only had a single branch to recover - this would be more complex if there was more than one head.
Then git stash
to stash currently uncommitted changes for inspection.
I was then able to git reset --hard
to the commit hash determined above.
git stash pop
also merged back pretty cleanly. I think I got pretty much everything I wanted back again.
If you didn't do anything "clever" between the backup point and the restore point all commits should be already there, you might be able to get away with just moving HEAD. You'll lose some of the changes not already committed though.
â Satà  Katsura
Nov 10 '17 at 14:29
That's what I did with thegit reset --hard HASH
command. The real trick is the bit before that, finding the hash of the commit you want to move to.
â sourcejedi
Nov 10 '17 at 14:58
add a comment |Â
up vote
2
down vote
accepted
Make a copy of the whole mess first, just in case.
git fsck
will show dangling objects and commits. Find the newest dangling commit. I fed all the commit hashes to gitk
, and it just shows the most "recent" one at the top. As well as only having a few commits to deal with, I only had a single branch to recover - this would be more complex if there was more than one head.
Then git stash
to stash currently uncommitted changes for inspection.
I was then able to git reset --hard
to the commit hash determined above.
git stash pop
also merged back pretty cleanly. I think I got pretty much everything I wanted back again.
If you didn't do anything "clever" between the backup point and the restore point all commits should be already there, you might be able to get away with just moving HEAD. You'll lose some of the changes not already committed though.
â Satà  Katsura
Nov 10 '17 at 14:29
That's what I did with thegit reset --hard HASH
command. The real trick is the bit before that, finding the hash of the commit you want to move to.
â sourcejedi
Nov 10 '17 at 14:58
add a comment |Â
up vote
2
down vote
accepted
up vote
2
down vote
accepted
Make a copy of the whole mess first, just in case.
git fsck
will show dangling objects and commits. Find the newest dangling commit. I fed all the commit hashes to gitk
, and it just shows the most "recent" one at the top. As well as only having a few commits to deal with, I only had a single branch to recover - this would be more complex if there was more than one head.
Then git stash
to stash currently uncommitted changes for inspection.
I was then able to git reset --hard
to the commit hash determined above.
git stash pop
also merged back pretty cleanly. I think I got pretty much everything I wanted back again.
Make a copy of the whole mess first, just in case.
git fsck
will show dangling objects and commits. Find the newest dangling commit. I fed all the commit hashes to gitk
, and it just shows the most "recent" one at the top. As well as only having a few commits to deal with, I only had a single branch to recover - this would be more complex if there was more than one head.
Then git stash
to stash currently uncommitted changes for inspection.
I was then able to git reset --hard
to the commit hash determined above.
git stash pop
also merged back pretty cleanly. I think I got pretty much everything I wanted back again.
answered Nov 10 '17 at 14:19
sourcejedi
19.5k32681
19.5k32681
If you didn't do anything "clever" between the backup point and the restore point all commits should be already there, you might be able to get away with just moving HEAD. You'll lose some of the changes not already committed though.
â Satà  Katsura
Nov 10 '17 at 14:29
That's what I did with thegit reset --hard HASH
command. The real trick is the bit before that, finding the hash of the commit you want to move to.
â sourcejedi
Nov 10 '17 at 14:58
add a comment |Â
If you didn't do anything "clever" between the backup point and the restore point all commits should be already there, you might be able to get away with just moving HEAD. You'll lose some of the changes not already committed though.
â Satà  Katsura
Nov 10 '17 at 14:29
That's what I did with thegit reset --hard HASH
command. The real trick is the bit before that, finding the hash of the commit you want to move to.
â sourcejedi
Nov 10 '17 at 14:58
If you didn't do anything "clever" between the backup point and the restore point all commits should be already there, you might be able to get away with just moving HEAD. You'll lose some of the changes not already committed though.
â Satà  Katsura
Nov 10 '17 at 14:29
If you didn't do anything "clever" between the backup point and the restore point all commits should be already there, you might be able to get away with just moving HEAD. You'll lose some of the changes not already committed though.
â Satà  Katsura
Nov 10 '17 at 14:29
That's what I did with the
git reset --hard HASH
command. The real trick is the bit before that, finding the hash of the commit you want to move to.â sourcejedi
Nov 10 '17 at 14:58
That's what I did with the
git reset --hard HASH
command. The real trick is the bit before that, finding the hash of the commit you want to move to.â sourcejedi
Nov 10 '17 at 14:58
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f403762%2frecover-a-git-repo-which-was-overwritten-with-an-older-version%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password