5

Intro and search

So I think I have made a grave mistake and I am concerned. I have parsed the forums for detached heads and I have come close to finding an answer, but the scenarios are too specific and not applicable to where I am at. If you find a specific thread that answers my question, please do link me.

For example: How can I reconcile detached HEAD with master/origin?

The guy has already done git rebase -i, which I have not. I've tried rebasing, but it didn't solve my issue.

Little background:

  • I am new to git; I use git only by myself
  • I own the remote repository
  • Needed old set of code, and it was time-sensitive issue
  • I picked up a little programming and am using it at workplace where no one else codes (so I can't quite ask for help)

Issue:

To access the old commit with working code, I did (probably the wrong thing):

git log
git checkout <hash-of-desired-old-commit>

I proceeded to finish the code. Thank goodness for version control! But shoot, why is git so complicated? How do I save this work? I am now in a detached head. Origin/Master is in some future commits that preferably should all be deleted.

What I have tried:

  • copied and pasted the entire folder elsewhere just for back-up
  • git add -A followed with git commit -m "oh shit, detached head commit" and git rebase master
  • git reset --hard HEAD~3 per recommendation here: Checkout old commit and make it a new commit

Question: How do I reconcile my detached head with origin/master? Once reconciled, do I need to git push --force or something (specifically with the --force flag)? There is work at this detached head, and I've read that the longer I wait, garbage collection may come and eat my lost branch. Sorry, I do lack any formal training in git... I am almost ready to just check out origin master and then rewrite the code.

Thank you in advance.

4

1 回答 1

3
于 2018-02-14T22:43:05.900 回答