日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Git 的origin和master解析

發布時間:2023/12/19 编程问答 46 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Git 的origin和master解析 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

首先要明確一點,對git的操作是圍繞3個大的步驟來展開的(其實幾乎所有的SCM都是這樣)

1.?????git取數據(git clone

2.?????改動代碼

3.?????將改動傳回gitgit push

3個步驟又涉及到兩個repository,一個是remote repository,再遠程服務器上,一個是local repository,再自己工作區上。其中

1, 3兩個步驟涉及到remote server/remote repository/remote branch

2涉及到local repository/local branchgit clone?會根據你指定的remote server/repository/branch,拷貝一個副本到你本地,再git push之前,你對所有文件的改動都是在你自己本地的local repository來做的,你的改動(local branch)remote branch是獨立(并行)的。Gitk顯示的就是local repository

?

clone完成之后,Git?會自動為你將此遠程倉庫命名為originorigin只相當于一個別名,運行git remote –v或者查看.git/config可以看到origin的含義)(guyue: 即origin是代表遠程倉庫的一個默認別名, 可以在項目工程目錄中.git/config文件中查看或修改),并下載其中所有的數據,建立一個指向它的master?分支的指針,我們用(遠程倉庫名)/(分支名)?這樣的形式表示遠程分支,所以origin/master指向的是一個remote branch(從那個branch我們clone數據到本地),但你無法在本地更改其數據。

同時,Git?會建立一個屬于你自己的本地master?分支,它指向的是你剛剛從remote server傳到你本地的副本。隨著你不斷的改動文件,git add, git commitmaster的指向會自動移動,你也可以通過mergefast forward)來移動master的指向。

?$git branch -a (to show all the branches git knows about)

* master

??remotes/origin/HEAD -> origin/master

??remotes/origin/master

?

$git branch -r (to show remote branches git knows about)

??origin/HEAD -> origin/master

??origin/master

?

可以發現,master就是local branchorigin/masterremote branchmaster is a branch in the local repository. remotes/origin/master is a branch named master on the remote named origin

$git diff origin/master master?show me the changes between the remote master branch and my master branch).

需要注意的是,remotes/origin/masterorigin/master的指向是相同的

$git diff origin/master remotes/origin/master

?

git push origin master

origin指定了你要push到哪個remote

master其實是一個“refspec”,正常的“refspec”的形式為”+<src>:<dst>”,冒號前表示local branch的名字,冒號后表示remote repository?branch的名字。注意,如果你省略了<dst>git就認為你想pushremote repository下和local branch相同名字的branch。聽起來有點拗口,再解釋下,push是怎么個push法,就是把本地branch指向的commit pushremote repository下的branch,比如

$git push origin master:master?(local repository中找到名字為masterbranch,使用它去更新remote repository下名字為masterbranch,如果remote repository下不存在名字是masterbranch,那么新建一個)

$git push origin master?(省略了<dst>,等價于“git push origin master:master”)

$git push origin master:refs/for/mybranch?(local repository中找到名字為masterbranch,用他去更新remote repository下面名字為mybranchbranch)

$git push origin HEAD:refs/for/mybranch?HEAD指向當前工作的branchmaster不一定指向當前工作的branch,所以我覺得用HEAD還比master好些)

$git push origin :mybranch?(再origin repository里面查找mybranch,刪除它。用一個空的去更新它,就相當于刪除了)

總結

以上是生活随笔為你收集整理的Git 的origin和master解析的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。