Git: Branch ahead by X commits

I preformed a git status on my local machine. It said "Your branch is ahead of 'origin/master' by 25 commits."

[me@myserver hours_portal]$ git status    
# On branch master
# Your branch is ahead of 'origin/master' by 25 commits.
#   (use "git push" to publish your local commits)
nothing to commit, working directory clean

Since the answer implied that I was ahead I ran a git push.

[me@myserver hours_portal]$ git push origin master
Username for 'https://remoteserver': me
Password for 'https://me@remoteserver':
To https://remoteserver/project.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://remoteserver/project.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first merge the remote changes (e.g.,
hint: 'git pull') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

Next, i preformed a git pull thinking that if there was a conflict it would fail.

[me@myserver hours_portal]$ git pull
Username for 'https://remoteserver': me
Password for 'https://me@remoteserver':
remote: Counting objects: 5, done.
remote: Compressing objects: 100% (5/5), done.
remote: Total 5 (delta 3), reused 0 (delta 0)
Unpacking objects: 100% (5/5), done.
From https://remoteserver/project
   778077b..9122bba  master     -> origin/master
Updating 84c39ac..9122bba
Fast-forward
 includes/calendar.inc.php | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

I was surprised the pull did not fail with conflict errors. So I did another git status.

[me@myserver hours_portal]$ git status
# On branch master
nothing to commit, working directory clean

My Questions:

Is there a way to figure out what those 25 original commits were?

Did I lose any data?

Was this a git pull bug I read about in git: Your branch is Ahead by X commits?


After git pull , we can see origin/master is updated from 778077b to 9122bba, and HEAD is updated from 84c39ac to 9122bba. So the 25 commits should be git log --oneline 778077b..84c39ac . You did not lose any data. This is not a git pull bug.

We could infer from the log the status of the branches before git pull is like:

local:
778077b-> origin/master
778077b-...-84c39ac-> master HEAD

server:
778077b-...-84c39ac-...-9122bba-> master

After the pull, if you run git push origin master , it should echo Everything up-to-date .


This is all perfect dude. Those 35 commits were on your branch that is local to you machine. When you did the push all commits went into repository. To check the conflict between master and branch, you need to switch to the master and get the latest by git pull and then switch back to your branch and perform the git merge operation that will bring if there is any conflict in your branch. Hope this helps you.

链接地址: http://www.djcxy.com/p/45084.html

上一篇: git:合并和rebase之间的区别

下一篇: Git:由X提交提前分支