1

How did that happen ?

I simply wanted to rename two of my git branches, local and remote. For the sake of understanding, let's say I wanted to rename the branch EVOL to DEV, and the branch DEL to DELIVERY.

To do so, I used the commands decribed here. It's quite simple. Firstly, I did, while in EVOL

git branch -m DEV
git push origin :EVOL DEV
git push origin -u DEV

Using gitk, I saw the change was effective, and did everything I wanted. So, to rename my second branch, I did the following commands (still in the now-called DEV branch)

git branch -m DEL DELIVERY
git push origin :DEL DELIVERY
git push origin -u DELIVERY

Here is where I failed. I should have done the last command in the DELIVERY branch, except I did not change, I was trying to be quick, and I didn't see the instruction on the webpage.

Consequences and problem

The DEV branch looks just like I wanted: same old EVOL branch, with a new name. However, the DELIVERY branch is just wrong, where I believe another branch was, months earlier than where DEL was. To be honest, I don't remember the use of the branch where DELIVERY is now, but ideally I would like to revert here as well whatever there was, to keep a clear history. Worse, it looks like I have lost track of my old DEL branch with its commit. I am unable to find them using gitk --all.

Since I realized my mistake, I didn't dare to try something, by fear of losing the old DEL commits. The last command I executed is that infamous git push origin -u DELIVERY

Question

Is it possible to revert that last command git push origin -u DELIVERY and/or to retrieve my commits that were on the DEL branch ?

superpg
  • 253
  • 2
  • 9
  • What do you mean by *"the `DELIVERY` branch is just wrong"*? Besides, I can't imagine how `git push origin -u DELIVERY` should be related to you losing the `DEL` branch. – alfunx Nov 08 '19 at 13:49
  • @alfunx To be honest, I don't know how precisely what happened to `DELIVERY`, even less explaining that in english. I edited my post to be as precise as I can. – superpg Nov 08 '19 at 13:57
  • Okay. Again, I don't think the push is related to the lost branch. Have a look at this to recover `DEL`: https://stackoverflow.com/questions/10099258/how-can-i-recover-a-lost-commit-in-git – alfunx Nov 08 '19 at 14:34
  • @alfunx Couldn't find my lost commits with reflog either unfortunately. Well, it will teach me a lesson I think. I am lucky enough that it was the `DEL` branch, I still have the last delivery on hand, will try to just fetch it and push again, but with another name, just in case. Perhaps `DELIVERY` was an already existing branch (I checked before manually by scrolling `gitk --all`, might have missed it), causing all of this trouble. – superpg Nov 08 '19 at 14:54
  • If the `DELIVERY` branch existed before, `git branch -m` should have failed. – alfunx Nov 08 '19 at 15:28
  • As @alfunx said, `git branch -m` should complain if you are trying to rename a branch to an in-use name. I wonder if this was a case-sensitivity issue. Git itself believes that branch names are case sensitive, i.e., `Hello` and `hello` are two different branches. So you can have one of each. Windows and MacOS file systems, by default, say that you *can't* have one of each: one just overwrites the other. When Git and these file systems fight, one of them wins, but there's no predicting who. – torek Nov 08 '19 at 21:27

0 Answers0