2

Its really confusing i trying push my all commits to production. But when i push to server 8840f9e pushing this.

My goal is push all my commits to production.

commit d06a8c7(HEAD)

commit e1467b4

commit 0ed15e7

commit 5886ab9

commit 0f8ee01

commit 8840f9e (production/master, master)
6
  • Hi @PuresvurenBathishig ! I'm afraid, your question is not clear to me. Could you provide more information on what you tried and what happens? Based on the log, it sounds like you have been creating commits that are on no branch, is that right?
    – lucidbrot
    Commented Oct 20, 2018 at 19:36
  • HI @lucidbrot i really don't know what going on here. When i commit its working and when i push its pushing 8840f9eaa0fbc8eaae592859d3e310bb91697468 this commit. Commented Oct 20, 2018 at 19:39
  • 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. Git log is telling you in parantheses that production/master and master are pointing to the commit 8840f9. You want master to point to your latest commit though.
    – lucidbrot
    Commented Oct 20, 2018 at 19:41
  • What is the output when you run git branch? If your problem is what I assume it is, it will be (HEAD detached from ...), is that right?
    – lucidbrot
    Commented Oct 20, 2018 at 19:52
  • @lucidbrot problem solved thanks sir you saved my day. Commented Oct 20, 2018 at 19:56

2 Answers 2

2

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.

0
  • Create a new temporary branch , say tempcommit
  • Checkout new branch
  • add commit to new branch
  • merge new branch to master

All in one command is like this

git branch tempcommit <commit id> && git checkout master && git merge tempbranch

Not the answer you're looking for? Browse other questions tagged or ask your own question.