Getting “error: no such commit” when trying to restore a deleted branch?


Getting “error: no such commit” when trying to restore a deleted branch?



I have already committed a file in Gerrit(pushed it), but I think, I, unfortunately, deleted that branch locally from which I committed. How to fix that? Please help.



I tried


git branch --contains 31436fd7200566967f85bfb1ee5425f9b599b908



but it shows


error: no such commit 31436fd7200566967f85bfb1ee5425f9b599b908



Edit: Yes I've git installed locally and I worked on the branch locally.



I got commit id from the Gerrit site, I've committed.



Okay, two days ago first there was a problem when I tried to commit the change, say A. I tried to submit it using "./logerrit submit master" but all I got was:


Counting objects: 32, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (32/32), done.
Writing objects: 100% (32/32), 100.46 KiB | 0 bytes/s, done.
Total 32 (delta 22), reused 0 (delta 0)
remote: Resolving deltas: 100% (22/22)
remote: Counting objects: 79789, done
remote: Processing changes: refs: 1, done
To ssh://logerrit/core
! [remote rejected] HEAD -> refs/for/master (change
https://gerrit.libreoffice.org/54112 closed)
error: failed to push some refs to 'ssh://logerrit/core'



So, it says that change id is same for two commits- the patch I'm committing and the patch that was already committed by me a few days ago and is merged now. I tried to do every possible thing which is mentioned on stack overflow or any other blogs- I tried to change the id, such that on next "git commit --amend" git automatically change the id, it was of no use as I was getting the same error, I also tried to fix the conflicts by removing the lines <<<<<<<<<<< ============ and >>>>>>>>>>> but am I correct with it? Is it the right way to resolve it? I then tried to "git rebase master" and then I got the error message:


First, rewinding head to replay your work on top of it...
Applying: smartart : test documents
Using index info to reconstruct a base tree...
M sd/qa/unit/import-tests-smartart.cxx
Falling back to patching base and 3-way merge...
Auto-merging sd/qa/unit/import-tests-smartart.cxx
CONFLICT (content): Merge conflict in sd/qa/unit/import-tests-
smartart.cxx
error: Failed to merge in the changes.
Patch failed at 0001 smartart : test documents
The copy of the patch that failed is found in: .git/rebase-
apply/patch

When you have resolved this problem, run "git rebase --continue".
If you prefer to skip this patch, run "git rebase --skip" instead.
To check out the original branch and stop rebasing, run "git rebase --abort".



I tried to change the branch, and then tried to again rebase the changes with the master as it was already up-to-date, but It was of no use. I then deleted the extra branches "locally" I created, and by mistake, I might have deleted one of the branch from which I've committed to Gerrit.



Now my question is:



Both first and second questions are related to differnt files/branch, but could be related to each other.





Please give a reason when downvoting a question, I don't think it's good to downvote without any reason, if there is any scope to explain my question better please let me know.
– Alohomora
Jun 29 at 9:24





Do you have git installed locally? And did you work on the branch locally (or at a pc of a differend coworker?)
– Ferrybig
Jun 29 at 9:34





where did you get the hash you are using? Is it same repository where you are running the command? How exactly you get it and what you did between getting it and running the command?
– max630
Jun 29 at 9:35






If the commit is known by the remote, you might not have pulled or fetched it into your local repository.
– Lasse Vågsæther Karlsen
Jun 29 at 10:23





You must define better what you really did. When you say "I commited in Gerrit" you mean you have commited locally, pushed do Gerrit and finally submitted (merged) in Gerrit, right? When you say "I deleted the branch" you mean you have deleted the local branch, correct? Or you have deleted the remote (Gerrit) branch?
– Marcelo Ávila de Oliveira
Jun 29 at 14:04





2 Answers
2



Since you are certain the commit exists on the remote, this should find it:


git branch -r --contains 31436fd7200566967f85bfb1ee5425f9b599b908



Once you know which remote branch the commit you want is on, let's call it <branch>, then you should be able to recreate that same branch locally with:


<branch>


# delete same-named local branch (if it exists)
git branch -D <branch>
# fetch latest branches from remote
git fetch
# checkout branch from remote
git checkout <branch>



Aknowledgements:





Sorry but I got error: no such commit 31436fd7200566967f85bfb1ee5425f9b599b908
– Alohomora
Jun 29 at 14:47






That indicates that you did not push it to the remote.
– Will Cain
Jun 29 at 14:59





gerrit.libreoffice.org/#/c/55891: Please see this patch
– Alohomora
Jun 29 at 15:56



Forget the commit 31436fd7200566967f85bfb1ee5425f9b599b908. If you really have merged your commit in Gerrit it is on the remote branch. To create and checkout a local branch from a remote branch execute:


git checkout -b local-branch remotebranch



Ex:


git checkout -b my-feature origin/release1.0





Does remotebranch will be "master" in case of mine? Please look into this commit: gerrit.libreoffice.org/#/c/55891
– Alohomora
Jun 29 at 15:20





No problem, to re-create the master branch you can execute: "git checkout -b master origin/master" or just "git checkout master" (if local branch master really doesn't exist)
– Marcelo Ávila de Oliveira
Jun 29 at 15:26





there's a difference, I can't name master to my local branch. Master branch in that community is basically where most of the commit happens, and is not someone's personal branch
– Alohomora
Jun 29 at 16:40





Ok, so execute: git checkout -b whatever-branch-name origin/master
– Marcelo Ávila de Oliveira
Jun 29 at 17:03





Sorry, It didn't help.
– Alohomora
2 days ago






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Comments

Popular posts from this blog

paramiko-expect timeout is happening after executing the command

Export result set on Dbeaver to CSV

Opening a url is failing in Swift