简体   繁体   English

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

[英]Git does not push changes to a branch if checkout and merge is done after a commit and push

I have a django application which I work on localhost in the alpha branch, and merge to master at intermittent intervals. 我有一个django应用程序,该应用程序在alpha分支的localhost上工作,并间歇地合并到master。 I have the following scenario. 我有以下情况。 I have worked on several commits in alpha, and upload to the git repo as below: 我已经在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

I now decide that this major bugfix needs to be in sync with master. 现在,我决定此主要错误修正需要与master同步。 So I do: 所以我做:

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

So I need to push this to remote, so that my project hosted on my webserver is in sync. 因此,我需要将此推送到远程,以便托管在我的Web服务器上的项目是同步的。

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

It seems that my changes in master, which are significant, have not been pushed to the central git repo. 似乎我对master所做的重要更改没有被推送到中央git repo中。

Checking, on my project's server: 在我项目的服务器上检查:

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.

So, though master on localhost has an important bugfix, this is not updated to the remote server. 因此,尽管localhost上的master具有重要的错误修正,但该修正未更新到远程服务器。 How can I avoid this? 如何避免这种情况?

Check the list of files changed between those commits: 检查在这些提交之间更改的文件列表:

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

Both when pushing: git diff 7b0f27ad..e16bb180 --name-only And when pulling in your second repo: git diff 33ac1a63..e16bb180 --name-only 两者同时推送: git diff 7b0f27ad..e16bb180 --name-onlygit diff 7b0f27ad..e16bb180 --name-only第二个git diff 33ac1a63..e16bb180 --name-onlygit diff 33ac1a63..e16bb180 --name-only

That will show you if you have pushed the right list of files (you can remove --name-only to inspect the actual changes) 这将显示您是否推送了正确的文件列表(可以删除--name-only以检查实际更改)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM