Fix a Git detached head?

前端 未结 23 1765
臣服心动
臣服心动 2020-11-22 05:42

I was doing some work in my repository and noticed a file had local changes. I didn\'t want them anymore so I deleted the file, thinking I can just checkout a fresh copy. I

23条回答
  •  暖寄归人
    2020-11-22 06:30

    When you're in a detached head situation and created new files, first make sure that these new files are added to the index, for example with:

    git add .
    

    But if you've only changed or deleted existing files, you can add (-a) and commit with a message (-m) at the the same time via:

    git commit -a -m "my adjustment message"
    

    Then you can simply create a new branch with your current state with:

    git checkout -b new_branch_name
    

    You'll have a new branch and all your adjustments will be there in that new branch. You can then continue to push to the remote and/or checkout/pull/merge as you please.

提交回复
热议问题