![](/img/trans.png)
[英]How to I get my local repo in sync wit ha file in master repo on github?
[英]How can I remove content from Github and get my repo in sync with my local code?
我在Github上托管我的博客,并且一直将我的新内容推送到源代码仓库中。 但是,这里到处都发生了变化,我已经删除/交换了博客的某些元素。 现在,我才意识到我所有的旧东西都在Github上脚。 就像我将所有东西推向Github一样。
我的问题:我可以使用什么命令使我的本地代码再次与我的Github存储库同步?
考虑到您通常会进行推送,我想在这种情况下服务器上的内容已更改,因此在这种情况下,您可以:
git pull # get the stuff from the server and merge it into your repo.
git push # push the combined stuff back out.
但是...这仍在使用看不见的魔法。 这些天我实际上在做以下事情:
git fetch # First fetch the server changes into your tracking branch
git merge # Merge those changes into yours
git push # Push those changes out.
然后,如果将来服务器上发生更改,则可以在进行本地更改之前执行以下操作:
git pull
虽然在这里我也更喜欢:
git fetch # Get the latest
git reset --hard origin/master # set your local to be the same as the tracking branch.
# Make changes locally
# git add . # Add the changes to git
# git commit -m"msg" # Commit the changes
因为这样可以避免意外地合并到错误的分支或忘记本地更改。
以上所有假定您只是在与master一起工作。 如今,我的大部分工作是在分支中完成的(顺便说一下,它与旧版本控制系统(例如CVS)中的分支不同)。
只需在本地git commit
并执行git push
Doc: http : //gitready.com/beginner/2009/01/21/pushing-and-pulling.html
如果我正确理解了您的问题,则希望摆脱Github存储库中的所有提交,并将其替换为本地的提交。 如果是这种情况,请尝试以下命令:
git push -f
这会将您的提交推送到服务器,而忽略已有的历史记录。
注意:您将丢失Github存储库中未与本地存储库共享的所有历史记录,因此请确保这是您想要的!
使用以下命令从远程提取数据
git pull
如果您有本地提交的内容,但远程不存在,则使用
git pull --rebase
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.