Git 的origin和master分析
<<關鍵是 中英文切換著打字太辛苦了轉載請註明出處>>
http://lishicongli.blog.163.com/blog/static/1468259020132125247302/
首先要明確一點,對git的操作是圍繞3個大的步驟來展開的(其實幾乎所有的SCM都是這樣)
1. 從git取資料(git clone)
2. 改動程式碼
3. 將改動傳回git(git push)
這3個步驟又涉及到兩個repository,一個是remote repository,再遠端伺服器上,一個是local repository,再自己工作區上。其中
1, 3兩個步驟涉及到remote server/remote repository/remote branch,
2涉及到local repository/local branch。git clone 會根據你指定的remote server/repository/branch,拷貝一個副本到你本地,再git push之前,你對所有檔案的改動都是在你自己本地的local repository來做的,你的改動(local branch)和remote branch是獨立(並行)的。Gitk顯示的就是local repository。
在clone完成之後,Git 會自動為你將此遠端倉庫命名為origin(origin只相當於一個別名,執行git remote –v或者檢視.git/config可以看到origin的含義),並下載其中所有的資料,建立一個指向它的master 分支的指標,我們用(遠端倉庫名)/(分支名) 這樣的形式表示遠端分支,所以origin/master指向的是一個remote branch(從那個branch我們clone資料到本地),但你無法在本地更改其資料。
同時,Git 會建立一個屬於你自己的本地master 分支,它指向的是你剛剛從remote server傳到你本地的副本。隨著你不斷的改動檔案,git add, git commit,master的指向會自動移動,你也可以通過merge(fast 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 branch,origin/master是remote branch(master 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/master和origin/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就認為你想push到remote repository下和local branch相同名字的branch。聽起來有點拗口,再解釋下,push是怎麼個push法,就是把本地branch指向的commit push到remote repository下的branch,比如
$git push origin master:master (在local repository中找到名字為master的branch,使用它去更新remote repository下名字為master的branch,如果remote repository下不存在名字是master的branch,那麼新建一個)
$git push origin master (省略了<dst>,等價於“git push origin master:master”)
$git push origin master:refs/for/mybranch (在local repository中找到名字為master的branch,用他去更新remote repository下面名字為mybranch的branch)
$git push origin HEAD:refs/for/mybranch (HEAD指向當前工作的branch,master不一定指向當前工作的branch,所以我覺得用HEAD還比master好些)
$git push origin :mybranch (再origin repository裡面查詢mybranch,刪除它。用一個空的去更新它,就相當於刪除了)
相關文章
- git關於origin和masterGitAST
- git merge origin master git merge origin/master區別GitAST
- (轉載)git pull origin master與git pull --rebase origin master的區別GitAST
- git學習:關於origin和masterGitAST
- 對 Git 分支 master 和 origin/master 的一些認識GitAST
- git - git push origin master 報錯GitAST
- Git branching: master vs. origin/master vs. remotes/origin/masterGitASTREM
- 在Git中,origin / master與origin master之間有什麼區別?GitAST
- git 上傳專案 報錯 git pull --rebase origin masterGitAST
- homebrew安裝問題(Failed during: git fetch origin master:refs/remotes/origin/master --tags --force)AIGitASTREM
- 初次git提交程式碼報錯:Push to origin/master was rejectedGitAST
- homebrew update 出現Failure while executing: git pull --quiet origin refs/heads/master:refs/remotes/origin/master解決方案AIWhileGitUIASTREM
- git pull如果提示merge衝突,先進行git reset --hard origin/master 後再git pullGitAST
- git中出現”the requested upstream branch ‘origin/master‘ does not exist“問題的解決GitAST
- git push origin master 時出現報錯 error: src refspec master does not match any error: failed to push someGitASTErrorAI
- git rebase masterGitAST
- Git 拉取 origin 分支Git
- git 從master建立新的分支GitAST
- git push --set-upstream originGit
- brew 報錯 error: Not a valid ref: refs/remotes/origin/master 的解決方法ErrorREMAST
- git使用報錯fatal: remote origin already exists.GitREM
- Git使用gh-pages分支切換到master分支錯誤pathspec master did not match any files known to gitGitAST
- git 當前分支 master 沒有對應的上游分支。GitAST
- git rebase master 分支出現一堆 ^MGitAST
- GIT使用過程出現(master|REBASE 1/10)GitAST
- show master logs 和 show master status 區別AST
- background-clip 和 background-origin
- Origin教程:DSC曲線的描述和繪製
- Git dev分支合併到master分支完美實戰GitdevAST
- git rebase後出現(master|REBASE 1/10)的解決辦法GitAST
- mysql master和slave配置MySqlAST
- MySQL Master/Slave Master/MasterMySqlAST
- Git 問題,一個 master,多個新功能分支,怎樣有序地合併和提交GitAST
- Android uncovers master-key 漏洞分析AndroidAST
- spark core原始碼分析3 Master HASpark原始碼AST
- background-origin和background-clip區別
- Git——如何從master檢出分支dev並推送到遠端?GitASTdev
- 解決 Jenkins 上 git 出現的 “ERROR: Error fetching remote repo 'origin'” 問題JenkinsGitErrorREM