[RUBY] [Git] The horrifying story of deleting the master branch ~ The answer is in English ~

It's been 3 days since I made the original app. I intended to define the requirements firmly, but it came out like this, "Oh, I have to do this too" "That? Misspelling" "What? What should I do here?" A series of such things. I was doing the work branch thinking that I had to commit diligently, and then I went back to another branch, and I couldn't understand why. ** "Delete the branch that has been merged once!" ** It seems that it was the beginning of hell that came up with that ...

What I've done

% git branch -D master     

"I did it while looking at the article. I don't know why this happened. I regret it." (Audio is processed to protect privacy

The master branch disappears. It's scary. After that, extract reflog with the following command

% git reflog
⬇️⬇️⬇️ Results below ⬇️⬇️⬇️

0422208 (HEAD -> master) HEAD@{0}: checkout:moving from user management function to master
444f2b7 (origin/User management function, User management function) HEAD@{1}: checkout: moving from master to User management function
0422208 (HEAD -> master) HEAD@{2}: checkout:moving from user management function to master
444f2b7 (origin/User management function, User management function) HEAD@{3}: checkout: moving from master to User management function
0422208 (HEAD -> master) HEAD@{4}: checkout:moving from user management function to master
444f2b7 (origin/User management function, User management function) HEAD@{5}: checkout: moving from master to User management function
0422208 (HEAD -> master) HEAD@{6}: checkout:moving from user management function to master

~ The following is omitted ~

Check the display of HEAD that came out and enter the corresponding number

% git branch master HEAD@{21}       

Zaoriku success. You did it!


And time went by, and the incident happened when the work on the new branch was over. Commit → Push → Do you want to check if it is reflected in master before deleting branch? ···that? ···that's strange ... Fetch Origin, huh? ... Why isn't the View file updated? e? !! No other files have been updated! why? !! When Fetch Origin

748108df3a83983d5d6af2bdd6af5266.png

Newer Commmits on Remote

It's already committed! Was angry. Where? It's not reflected ... When I check it, it looks like this.

% git branch -a  

* master
Create new table
User management function
  remotes/origin/master
  remotes/origin/Create new table
  remotes/origin/User management function

There are remotes! I don't know why it isn't reflected. I'm addicted to it for about 2 hours. Did the resurrection spell go wrong? Was that Zaoral, not Zaoriku? Thinking about that, I read the English article that came out after searching for an error sentence because it just didn't work.

Apparently it's an error that comes from not having a tracking branch set in the master branch of the local repository (I'm not sure what you're saying) It will be recovered by cloning the repository.

The feeling is that I deleted it so the master branch wasn't back in perfect condition! What do you mean? I will try it for the time being.

% git branch -u origin/master

Now you can pull nicely! I was relieved ... I've searched a lot, but I don't understand what the "-u" command means. What is the command doing? remotes/origin/master I thought it was a remote branch, but it's different. I've read it several times but it's really difficult. There are still many things I don't understand. It's rewarding.

I referred to

https://qiita.com/forest1/items/db5ac003d310449743ca

Thank you very much.

Recommended Posts

[Git] The horrifying story of deleting the master branch ~ The answer is in English ~
The story of writing Java in Emacs
The story of low-level string comparison in Java
The story of making ordinary Othello in Java
The story of learning Java in the first programming
In Time.strptime,% j (total date of the year) is
The story of an Illegal State Exception in Jetty.
The story that .java is also built in Unity 2018
Determine that the value is a multiple of 〇 in Ruby
What is the representation of domain knowledge in the [DDD] model?
The story of throwing BLOB data from EXCEL in DBUnit
The milliseconds to set in /lib/calendars.properties of Java jre is UTC
[Reference example] Copyright is described in the comment of the source code.