![](/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.