Question

I have some git repo with alot of remotes, some of remote branches a unique and i have not local tracking branches for it.

Today I did mistake on changing a remote url (I used remote1 instead of remote2).

After git fetch --all my remote1 was rewritten (i see + before commit sha)

It's very bad, because remote1 now not accessible for me, and i cant modify url back and fetch.

Is it possible restore remote1 branches from my local repo after this wrong fetch?

Was it helpful?

Solution

Git logs everything that happened to references (like branch tips and remote branch tips) in the reflog, you have to dive in it to find the previous SHA of the remote.

To search the git reflog, enter git reflog, and search for the before-last mention of (refs/remotes/remote/branch). It will give you a SHA.

Then you can restore the remote reference to this SHA by running

git update-ref refs/remotes/remote1/branch

EDIT you can try to find dangling commits with Lost Last Git Commit.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top