如果在提交并推送之后完成检出和合并,则Git不会将更改推送到分支机构

时间:2018-11-27 04:03:09

标签: git

我有一个Django应用程序,该应用程序在alpha分支的localhost上工作,并间歇地合并到master。我有以下情况。我已经在Alpha中进行了几次提交,并按如下所示将其上传到git repo:

$ git status
On branch alpha
Your branch is up to date with 'origin/alpha'.

Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)

    modified:   clinic/__pycache__/views.cpython-36.pyc
    modified:   clinic/views.py

no changes added to commit (use "git add" and/or "git commit -a")

joel@hp:~/myrepo$ git commit -a
[alpha e16bb180] Fixed an issue in checking for clinic membership. There was no check for if the user was not authenticated
2 files changed, 6 insertions(+)

joel@hp:~/myrepo$ git push
Counting objects: 6, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (6/6), done.
Writing objects: 100% (6/6), 1.46 KiB | 1.46 MiB/s, done.
Total 6 (delta 5), reused 0 (delta 0)
remote: 
remote: Create pull request for alpha:
remote:   https://bitbucket.org/myrepo
remote: 
To bitbucket.org:user/myrepo.git
33ac1a63..e16bb180  alpha -> alpha

我现在决定此主要错误修正需要与master同步。所以我这样做:

joel@hp:~/myrepo$ git checkout master
Switched to branch 'master'
Your branch is up to date with 'origin/master'.
joel@hp:~/myrepo$ git merge alpha
Updating 7b0f27ad..e16bb180
Fast-forward
appointments/__pycache__/models.cpython-36.pyc                             | Bin 26755 -> 26755 bytes
appointments/__pycache__/views.cpython-36.pyc                              | Bin 53867 -> 53867 bytes
appointments/migrations/__pycache__/0058_auto_20181122_2143.cpython-36.pyc | Bin 613 -> 613 bytes
appointments/templates/site/test.html                                      |  11 +++++++++++
clinic/__pycache__/urls.cpython-36.pyc                                     | Bin 9875 -> 9875 bytes
clinic/__pycache__/views.cpython-36.pyc                                    | Bin 156447 -> 156597 bytes
clinic/templatetags/__pycache__/__init__.cpython-36.pyc                    | Bin 140 -> 140 bytes
clinic/templatetags/__pycache__/customtags.cpython-36.pyc                  | Bin 1246 -> 1246 bytes
clinic/views.py                                                            |   6 ++++++
myrepo/__pycache__/settings.cpython-36.pyc                         | Bin 4541 -> 4541 bytes
myrepo/settings.py                                                 |   2 +-
11 files changed, 18 insertions(+), 1 deletion(-)
create mode 100644 appointments/templates/site/test.html
joel@hp:~/myrepo$ git push
Total 0 (delta 0), reused 0 (delta 0)
To bitbucket.org:user/myrepo.git
7b0f27ad..e16bb180  master -> master

所以我需要将其推送到远程,以便托管在我的Web服务器上的项目是同步的。

joel@hp:~/myrepo$ git push
Total 0 (delta 0), reused 0 (delta 0)
To bitbucket.org:user/myrepo.git
7b0f27ad..e16bb180  master -> master

看来,我对master所做的重大更改尚未推送到中央git repo中。

在我项目的服务器上进行检查:

root@myopip:/home/joel/myappointments# git checkout alpha
Switched to branch 'alpha'
Your branch is behind 'origin/alpha' by 1 commit, and can be fast-forwarded.
(use "git pull" to update your local branch)
root@myopip:/home/joel/myappointments# git pull
Updating 33ac1a63..e16bb180
Fast-forward
clinic/__pycache__/views.cpython-36.pyc | Bin 156447 -> 156597 bytes
clinic/views.py                         |   6 ++++++
2 files changed, 6 insertions(+)
root@myopip:/home/joel/myappointments# git checkout master
Switched to branch 'master'
Your branch is up to date with 'origin/master'.
root@myopip:/home/joel/myappointments# git pull
Already up to date.

因此,尽管localhost上的master具有重要的错误修正,但该修正未更新到远程服务器。 如何避免这种情况?

1 个答案:

答案 0 :(得分:0)

检查在这些提交之间更改的文件列表:

git diff <a commit sha1>...<b commit sha2> --name-only # b is after a in time

两者同时按下:git diff 7b0f27ad..e16bb180 --name-only 而在引入第二个仓库时:git diff 33ac1a63..e16bb180 --name-only

这将显示您是否推送了正确的文件列表(可以删除--name-only来检查实际更改)