[英]Git- local master branch appears to be broken
I am working on a Python/ Django project, using Git to manage my version control. 我正在使用Git管理我的版本控制的Python / Django项目。
On the live server, the website currently works as expected, however, I have made a couple of changes to the layout/ presentation of one of the views
on my local copy. 在实时服务器上,该网站当前可以正常运行,但是,我对本地副本中一个views
的布局/显示方式进行了一些更改。
To do this, when my local master branch was up to date with the live version, I created a new branch from master called pipelineProject
, and started working on that branch. 为此,当我的本地master分支与最新版本保持同步时,我从master创建了一个名为pipelineProject
的新分支,并开始在该分支上工作。 While making changes on pipelineProject
, I 'broke' the website during the course of making changes, and had to revert that branch to the state of master a couple of times. 在pipelineProject
上进行更改时,我在进行更改的过程中“中断”了该网站,并且不得不将该分支恢复为master状态几次。
I have now got my pipelineProject
branch to a state where the changes I wanted to make work correctly- I have run git add -A
and git commit -m 'message'
to ensure that my working pipelineProject
branch is backed up. 现在,我已将pipelineProject
分支设置为要正确执行更改的状态-我已运行git add -A
和git commit -m 'message'
以确保备份了我的工作pipelineProject
分支。
However, after backing up pipelineProject
, I then checked out master
, as I obviously wanted to merge my changes with master
, and before merging my changes, I tried loading my website in the browser while on master
branch- but for some reason this is now broken... although the website loads, all of the styling has disappeared- and the page just displays a list of the HTML elements used in the page (hyperlinks, titles & a few variable names from the code) 但是,在备份pipelineProject
,我随后检出了master
,因为我显然想将更改与master
合并,并且在合并更改之前,我尝试在master
分支上的浏览器中加载我的网站-但由于某些原因,现在损坏...尽管网站已加载,但所有样式均已消失-并且页面仅显示页面中使用的HTML元素的列表(超链接,标题和代码中的一些变量名)
The live version of the website is still in the same working state as it was before I started working on these changes, so I tried switching to my local master
branch, and running git pull origin master
to update my local master
copy with the copy that is currently running on the server. 网站的实时版本仍与开始进行这些更改之前的工作状态相同,因此我尝试切换到本地master
分支,并运行git pull origin master
以使用以下副本更新本地master
副本:当前正在服务器上运行。
When I did this, git displayed a message saying: 当我这样做时,git显示一条消息:
Already up-to-date 已经是最新的
I don't understand why this is... if my local master is up-to-date, then why am I able to view the website correctly on the live server, but when I view it on my local server, it doesn't display correctly...? 我不明白为什么会这样...如果我的本地管理员是最新的,那么为什么我可以在实时服务器上正确查看该网站,但是当我在本地服务器上查看该网站时,却无法不能正确显示...?
When I view the website locally on my pipelineProject
branch it all works correctly (and the changes that I have made are displayed as expected), but I don't want to merge my pipelineProject
branch into my local master
branch in case I lose the changes that I have successfully made. 当我在pipelineProject
分支上本地查看网站时,所有网站都可以正常运行(并且所做的更改将按预期显示),但是我不想将pipelineProject
分支合并到本地master
分支中,以防丢失更改我已经成功做到的。
Why is it that my local master
is broken, when the live
master works, even though the two are identical? 即使live
主机工作时,我的本地master
为什么会损坏? How can I fix this before pushing my changes to the live server? 在将更改推送到实时服务器之前,如何解决此问题?
Edit 编辑
Just a thought: since my pipelineProject
branch seems be working correctly, could I replace my local master branch with this one, and then push that to the server? 只是想一想:既然我的pipelineProject
分支似乎工作正常,是否可以用这个替换我的本地主分支,然后将其推送到服务器?
Is there a reason why my local master would be broken even though it is up-to-date with the live one when the live one works? 当现场工作的人与现场工作的人保持最新时,我的本地主人会被打扰吗?
For your questions: 对于您的问题:
git checkout pipelineProject
and git branch pipelineProject -u origin/master
, then delete local master branch git branch –D master
, finally rename pipelineProject to master git branch -m pipelineProject master
首先,您应该使pipelineProject分支跟踪源/主git checkout pipelineProject
,使用git checkout pipelineProject
和git branch pipelineProject -u origin/master
,然后删除本地主分支git branch –D master
,最后将pipelineProject重命名为master git branch -m pipelineProject master
git status
to check), and you can view commits which are ahead of the origin/master, use git log origin/master..master
. 这是由于本地master分支在远程的origin / master分支之前引起的(可以使用git status
进行检查),并且可以使用git log origin/master..master
来查看在origin / master之前的提交。 So for your situation you need to drop the “broken” commit, you can use git reset --hard <commit id which you want go back>
(if you do't willing to delete master branch) 因此,根据您的情况,您需要删除“断开”的提交,可以使用git reset --hard <commit id which you want go back>
(如果您不愿意删除master分支) Make sure your local & remote master are in same commit-sha 确保您的本地和远程主服务器位于同一提交窗口中
$ git checkout pipelineProject # go to your pipelineProject branch
$ git branch -D master # delete the local master branch
Then go to online and copy the master's last commit sha 然后上网并复制主人的最后一次提交
$ git checkout paste-commit-sha-here # go to the remote master's last commit
$ git checkout -b master # create & checkout local master branch
Replace local master with pipelineProject
and push to server 用pipelineProject
替换本地主服务器并推送到服务器
$ git checkout pipelineProject # go to your pipelineProject branch
$ git branch -D master # delete the local master branch
$ git checkout -b master # create & checkout new local master
$ git push -f origin master # push to server forcely
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.