Git:由X提交提前分支

我在本地机器上执行了git状态。 它说:“你的分支在25次提交之前领先于'origin / master'。”

[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

由于答案意味着我在前面,我跑了一个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.

接下来,我进行了一次git pull,认为如果发生冲突就会失败。

[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(-)

我很惊讶,拉并没有因冲突错误而失败。 所以我做了另一个git状态。

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

我的问题:

有没有办法找出这25个原始提交是什么?

我有没有丢失任何数据?

这是一个混帐拉错误,我在git中读到:你的分支是提前X提交?


git pull ,我们可以看到origin / master从778077b更新为9122bba,并且HEAD从84c39ac更新为9122bba。 所以25个提交应该是git log --oneline 778077b..84c39ac 。 你没有丢失任何数据。 这不是一个git pull bug。

我们可以从日志中推断git pull之前分支的状态如下:

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

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

在拉动之后,如果你运行git push origin master ,它应该回显Everything up-to-date


这是所有完美的家伙。 这35个提交都在你的分支机构上,而你本地的机器。 当你把所有提交都推送到仓库时。 为了检查master和branch之间的冲突,你需要切换到master,并通过git pull获取最新的信息,然后切换回你的分支并执行git合并操作,如果你的分支有任何冲突,将会带来git合并操作。 希望这可以帮助你。

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

上一篇: Git: Branch ahead by X commits

下一篇: How to clear "This branch is N commits ahead of master"?