git fetch 的簡單用法:更新遠程代碼到本地倉庫

git fetch 的簡單用法:更新遠程代碼到本地倉庫

作者:com360更新於 05月10日訪問(1486)評論(10)

Git中從遠程的分支獲取最新的版本到本地方式如下,如何更新下載到代碼到本地,請參閱ice的博客基於Github參與eoe的開源項目指南方式一1. 查看遠程倉庫

123456

$ git remote -veoecn https://github.com/eoecn/android-app.git (fetch)eoecn https://github.com/eoecn/android-app.git (push)origin https://github.com/com360/android-app.git (fetch)origin https://github.com/com360/android-app.git (push)su@SUCHANGLI /e/eoe_client/android-app (master)

從上面的結果可以看出,遠程倉庫有兩個,一個是eoecn,一個是origin2 ,從遠程獲取最新版本到本地

1234

$ git fetch origin masterFrom https://github.com/com360/android-app * branch master -> FETCH_HEADsu@SUCHANGLI /e/eoe_client/android-app (master)

$ git fetch origin master 這句的意思是:從遠程的origin倉庫的master分支下載代碼到本地的origin master3. 比較本地的倉庫和遠程參考的區別

12

$ git log -p master.. origin/mastersu@SUCHANGLI /e/eoe_client/android-app (master)

因為我的本地倉庫和遠程倉庫代碼相同所以沒有其他任何信息4. 把遠程下載下來的代碼合併到本地倉庫,遠程的和本地的合併

123

$ git merge origin/masterAlready up-to-date.su@SUCHANGLI /e/eoe_client/android-app (master)

我的本地參考代碼和遠程代碼相同,所以是Already up-to-date

以上的方式有點不好理解,大家可以使用下面的方式,並且很安全方式二1.查看遠程分支,和上面的第一步相同2. 從遠程獲取最新版本到本地

1234

$ git fetch origin master:tempFrom https://github.com/com360/android-app * [new branch] master -> tempsu@SUCHANGLI /e/eoe_client/android-app (master)

git fetch origin master:temp 這句命令的意思是:從遠程的origin倉庫的master分支下載到本地並新建一個分支temp

  1. 比較本地的倉庫和遠程參考的區別

12

$ git diff tempsu@SUCHANGLI /e/eoe_client/android-app (master)

命令的意思是:比較master分支和temp分支的不同由於我的沒有區別就沒有顯示其他信息4. 合併temp分支到master分支

123

$ git merge tempAlready up-to-date.su@SUCHANGLI /e/eoe_client/android-app (master)

由於沒有區別,所以顯示Already up-to-date.合併的時候可能會出現衝突,有時間了再把如何處理衝突寫一篇博客補充上。5.如果不想要temp分支了,可以刪除此分支

123

$ git branch -d tempDeleted branch temp (was d6d48cc).su@SUCHANGLI /e/eoe_client/android-app (master)

如果該分支沒有合併到主分支會報錯,可以用以下命令強制刪除git branch -D <分支名>

總結:方式二更好理解,更安全,對於pull也可以更新代碼到本地,相當於fetch+merge,多人寫作的話不夠安全。如有錯誤請指正

聲明:eoe文章著作權屬於作者,受法律保護,轉載時請務必以超鏈接形式附帶如下信息

原文作者: com360

原文地址: http://my.eoe.cn/com360/archive/3533.html

推薦閱讀:

qq免費黑色皮膚代碼 qq空間免費代碼 qq空間免費皮膚代碼七七空間站
代碼888
用代碼寫的漂亮字體
html日誌常用代碼
圖片製作的方法及代碼

TAG:代碼 | 簡單 | 倉庫 | 更新 |