简体   繁体   English

如何从Github中删除内容并使我的存储库与本地代码同步?

[英]How can I remove content from Github and get my repo in sync with my local code?

I am hosting my blog on Github and have always pushed my new content to the source repo. 我在Github上托管我的博客,并且一直将我的新内容推送到源代码仓库中。 However, things have changed here and there and I have removed/exchanged some elements of my blog. 但是,这里到处都发生了变化,我已经删除/交换了博客的某些元素。 Now, I just realized that my all my old stuff is stil on Github. 现在,我才意识到我所有的旧东西都在Github上脚。 It is like that there is everything I have ever pushed to Github. 就像我将所有东西推向Github一样。

My question: What command can I use to get my local code in sync with my Github repo again? 我的问题:我可以使用什么命令使我的本地代码再次与我的Github存储库同步?

Given that you normally push, I am guessing that in this case there is changed content on the server, so in this case you can: 考虑到您通常会进行推送,我想在这种情况下服务器上的内容已更改,因此在这种情况下,您可以:

git pull # get the stuff from the server and merge it into your repo.

git push # push the combined stuff back out.

However... this is still using unseen magic. 但是...这仍在使用看不见的魔法。 What I actually do these days is the following: 这些天我实际上在做以下事情:

git fetch  # First fetch the server changes into your tracking branch
git merge  # Merge those changes into yours
git push   # Push those changes out.

Then, in the future, if there are changes on the server, before making local changes you can do: 然后,如果将来服务器上发生更改,则可以在进行本地更改之前执行以下操作:

git pull  

Although here too I prefer: 虽然在这里我也更喜欢:

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

because it avoids accidentally doing an unintended merge to the wrong branch or forgetting about local changes. 因为这样可以避免意外地合并到错误的分支或忘记本地更改。

All the above assumes you are just working with master. 以上所有假定您只是在与master一起工作。 These days most of my work is done in branches (which incidentally are NOT the same as branches in older Version Control systems such as CVS). 如今,我的大部分工作是在分支中完成的(顺便说一下,它与旧版本控制系统(例如CVS)中的分支不同)。

Just git commit on your local and do a git push 只需在本地git commit并执行git push

Doc: http://gitready.com/beginner/2009/01/21/pushing-and-pulling.html Doc: http : //gitready.com/beginner/2009/01/21/pushing-and-pulling.html

If I understood your question correctly, you want to get rid of all commits that are in the Github repo, and replace them with the commits that you have locally. 如果我正确理解了您的问题,则希望摆脱Github存储库中的所有提交,并将其替换为本地的提交。 If that is the case, try the following command: 如果是这种情况,请尝试以下命令:

git push -f

This will push your commits to the server ignoring the history that was already there. 这会将您的提交推送到服务器,而忽略已有的历史记录。

BEWARE: You will lose all the history from your Github repo that is not shared with your local repo, so make sure this is what you want! 注意:您将丢失Github存储库中未与本地存储库共享的所有历史记录,因此请确保这是您想要的!

Use below command to pull data from remote 使用以下命令从远程提取数据

git pull git pull

If you have locally made commits which are not present on remote then use 如果您有本地提交的内容,但远程不存在,则使用

git pull --rebase git pull --rebase

暂无
暂无

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

相关问题 如何在github上的主仓库中获取与本地文件同步的本地仓库? - How to I get my local repo in sync wit ha file in master repo on github? 如何删除 git repo 中的所有文件并从本地 git repo 更新/推送? - How can I remove all files in my git repo and update/push from my local git repo? 如何检索在github上对本地存储库的提交? - How can I retrieve a commit made on github to my local repo? 如何减少github存储库的实际大小? (而不仅仅是我的本地结帐) - How can I reduce the actual size of my github repo? (rather than just my local checkout) 我有两个本地存储库,一个在学校一个在家里,另一个在 github 上的远程存储库,我如何从一个本地存储库提交以同步到另一个本地存储库 - i have two local repos, one at school one at home, and the remote repo on github, how do i get commits from one local repo to sync to the other local 如何用github上的本地仓库覆盖本地仓库? - How do I overwrite my local repo with the one on github? 如何将本地文件夹推送到我的 github 存储库? - How do I push a local folder to my github repo? 如何将本地主目录仓库中添加的新目录同步到 github - How to sync new directory added in my local main directory repo to github 如何删除特定 Github 存储库的“贡献的存储库”? - How do I remove my “repository contributed to” for a specific Github repo? 如何从GitHUB到本地计算机进行更改? - How do I get changes from GitHUB to my local machine?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM