S
S
Solenoid22002018-07-13 00:37:02
git
Solenoid2200, 2018-07-13 00:37:02

How to defeat the detached HEAD state?

Description of the problem: Two developers (Petya and Vasya) started to make the same project (project2018wm) each in their own way. Everyone makes their own commits to their Github repository. When they made 10 commits, they consulted and decided that Vasya's version is preferable, with the exception of the last two commits.
Question: How can Petya make his next commit (11th) make the state of his repository on github identical to the state of Vasya's project after his 8th commit?
I (Petya) tried this: 1. I deleted my project locally on my computer. 2. Cloned Vasya's project from github to my computer. 3. git checkout hash_8_of_Vasya_commit 4. Now I have all project files like Vasya's after commit 8 5. git remote set-url origin url_to_Petya_repository.git
Well, further in IDEA when I try: VCS --> Commit... --> Commit and push... I get the message "The Git repository C:\project2018wm is in the detached HEAD state"
How to do it? (Not uploading the project again)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jcmvbkbc, 2018-07-13
@jcmvbkbc

I (Petya) tried this:
1. I deleted my project locally on my computer.
2. Cloned Vasya's project from github to my computer.
3. git checkout Vasya's 8th_commit hash

It was at this moment that detached HEAD happened.
Not necessary, because step 2 already did it.
Depends on how you decide to deal with history. There are several options:
- throw out two unnecessary commits completely and rewrite the history starting from this point. To do this, at step 3, it was necessary to do git reset --hard хэш_8_го_коммита_Васи, and when pushing to the repository, push with the -f key
- roll back two unnecessary commits, leaving them in the history. To do this, in step 3 you had to do
git revert хэш_10_го_коммита; git revert хэш_9_го_коммита

- give birth to a new branch from the 8th commit and develop further in it. To do this, in step 3 you had to do
git checkout хэш_8_го_коммита_Васи -b имя_новой_ветки

In your current state, I would do the following:
git stash
git checkout master # или имя ветки в которой были 8 хороших коммитов
действия из выбранного варианта из перечисленных выше
git stash pop

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question