Skip to main content
The 2024 Developer Survey results are live! See the results
added 2 characters in body
Source Link
lucidbrot
  • 6k
  • 3
  • 44
  • 70

tl;dr
You could try git branch tempbranch d06a8c7d9a && git checkout master && git merge tempbranchgit branch tempbranch d06a8c7d9a && git checkout master && git merge tempbranch to get the commit onto your master branch, and then do the push to production.


Usually, git commits are on some branch. Maybe on multiple, but that's not relevant here.
When you usually work, you are supposed to have some branch checked out - yours is called master.
But it can happen that you leave the branch, and create commits of your new changes without telling git on which branch they belong. In that case, git will enter something called a "detached head state".

For example:

git init
touch file.txt
git add file.txt
git commit -m "initial commit"

Creates a file and commits it. Let us modify the file and commit again, so we have two commits. If you now explicitly git checkout HEAD~, i.e. if you check out the first commit, you are no longer on the master branch. This is just one example of how to get to that state.

If you now create a new commit, git will warn you:

$ git checkout HEAD^
Note: checking out 'HEAD^'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b <new-branch-name>

HEAD is now at 24ebade initial commit

To get the new commits back to some branch, you can do what it recommends you.
Create a new branch which points to your latest commit, using git checkout -b tempBranch for example.

It is possible, that you have some commits on master, that contradict your changes that happened in this detached HEAD state which is now on tempBranch. Because of that, you might need to resolve merge conflicts.

git checkout master
git merge tempbranch

makes sure both your commit histories are merged together into your master branch. After resolving merge conflicts, you are back at a state which you're used to, and can push as usual.
To clean up, since you do not need the temporary branch tempBranch anymore, you can delete it using git branch -d tempbBranch.

tl;dr
You could try git branch tempbranch d06a8c7d9a && git checkout master && git merge tempbranch to get the commit onto your master branch, and then do the push to production.


Usually, git commits are on some branch. Maybe on multiple, but that's not relevant here.
When you usually work, you are supposed to have some branch checked out - yours is called master.
But it can happen that you leave the branch, and create commits of your new changes without telling git on which branch they belong. In that case, git will enter something called a "detached head state".

For example:

git init
touch file.txt
git add file.txt
git commit -m "initial commit"

Creates a file and commits it. Let us modify the file and commit again, so we have two commits. If you now explicitly git checkout HEAD~, i.e. if you check out the first commit, you are no longer on the master branch. This is just one example of how to get to that state.

If you now create a new commit, git will warn you:

$ git checkout HEAD^
Note: checking out 'HEAD^'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b <new-branch-name>

HEAD is now at 24ebade initial commit

To get the new commits back to some branch, you can do what it recommends you.
Create a new branch which points to your latest commit, using git checkout -b tempBranch for example.

It is possible, that you have some commits on master, that contradict your changes that happened in this detached HEAD state which is now on tempBranch. Because of that, you might need to resolve merge conflicts.

git checkout master
git merge tempbranch

makes sure both your commit histories are merged together into your master branch. After resolving merge conflicts, you are back at a state which you're used to, and can push as usual.
To clean up, since you do not need the temporary branch tempBranch anymore, you can delete it using git branch -d tempbBranch.

tl;dr
You could try git branch tempbranch d06a8c7d9a && git checkout master && git merge tempbranch to get the commit onto your master branch, and then do the push to production.


Usually, git commits are on some branch. Maybe on multiple, but that's not relevant here.
When you usually work, you are supposed to have some branch checked out - yours is called master.
But it can happen that you leave the branch, and create commits of your new changes without telling git on which branch they belong. In that case, git will enter something called a "detached head state".

For example:

git init
touch file.txt
git add file.txt
git commit -m "initial commit"

Creates a file and commits it. Let us modify the file and commit again, so we have two commits. If you now explicitly git checkout HEAD~, i.e. if you check out the first commit, you are no longer on the master branch. This is just one example of how to get to that state.

If you now create a new commit, git will warn you:

$ git checkout HEAD^
Note: checking out 'HEAD^'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b <new-branch-name>

HEAD is now at 24ebade initial commit

To get the new commits back to some branch, you can do what it recommends you.
Create a new branch which points to your latest commit, using git checkout -b tempBranch for example.

It is possible, that you have some commits on master, that contradict your changes that happened in this detached HEAD state which is now on tempBranch. Because of that, you might need to resolve merge conflicts.

git checkout master
git merge tempbranch

makes sure both your commit histories are merged together into your master branch. After resolving merge conflicts, you are back at a state which you're used to, and can push as usual.
To clean up, since you do not need the temporary branch tempBranch anymore, you can delete it using git branch -d tempbBranch.

Source Link
lucidbrot
  • 6k
  • 3
  • 44
  • 70

tl;dr
You could try git branch tempbranch d06a8c7d9a && git checkout master && git merge tempbranch to get the commit onto your master branch, and then do the push to production.


Usually, git commits are on some branch. Maybe on multiple, but that's not relevant here.
When you usually work, you are supposed to have some branch checked out - yours is called master.
But it can happen that you leave the branch, and create commits of your new changes without telling git on which branch they belong. In that case, git will enter something called a "detached head state".

For example:

git init
touch file.txt
git add file.txt
git commit -m "initial commit"

Creates a file and commits it. Let us modify the file and commit again, so we have two commits. If you now explicitly git checkout HEAD~, i.e. if you check out the first commit, you are no longer on the master branch. This is just one example of how to get to that state.

If you now create a new commit, git will warn you:

$ git checkout HEAD^
Note: checking out 'HEAD^'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b <new-branch-name>

HEAD is now at 24ebade initial commit

To get the new commits back to some branch, you can do what it recommends you.
Create a new branch which points to your latest commit, using git checkout -b tempBranch for example.

It is possible, that you have some commits on master, that contradict your changes that happened in this detached HEAD state which is now on tempBranch. Because of that, you might need to resolve merge conflicts.

git checkout master
git merge tempbranch

makes sure both your commit histories are merged together into your master branch. After resolving merge conflicts, you are back at a state which you're used to, and can push as usual.
To clean up, since you do not need the temporary branch tempBranch anymore, you can delete it using git branch -d tempbBranch.