git 分支使用疑問 - Linux

By Damian
at 2012-02-03T00:54
at 2012-02-03T00:54
Table of Contents
※ 引述《shihyuyao (shihyuyao)》之銘言:
: 分支的切換是只能local端嗎?
: git branch -r
: octopress/HEAD -> octopress/master
: octopress/configuration
: octopress/edge
: octopress/gh-pages
: octopress/master
: octopress/move_rakefile_configs
: octopress/rake_minify_js
: octopress/refactor_code_highlight
: octopress/refactor_deployment
: octopress/refactor_js
: octopress/rubygemcli
: octopress/site
: octopress/site-deploy-test
: octopress/subdir
: octopress/thor
: 假設我要切到 octopress/configuration 分支
: git checkout octopress/configuration
: 出現下面錯誤?
: error: You have local changes to 'Rakefile'; cannot switch branches.
: 還有 用 git clone 下載是預設下載遠端的 master的檔案嗎?
: 要如何下載分支的檔案?
: 謝謝
你的問題其實不在於是不是local端 而是因為你Rakefile有改過(local changes)
而你checkout其他branch的話 可能造成你這個修改不見
為了安全起見 git不允許你切換branch
想解決這個問題 你可以先commit local changes 這樣你的working copy就是clean的
不過通常不要為了暫時的切換亂commit比較好 有個好作法是利用 git stash
他會暫時把你現在的working copy存下來 然後讓working copy變成跟HEAD一樣
也就是clean的 你可以stash很多很多working copy 像stack一樣一個個疊上去
等你暫時要做的事情結束後 切回原來branch 再用 git stash pop把剛剛暫存的東西
復原回來就好了~
要注意你如果在HEAD=A的時候stash 然後在HEAD=B的時候pop
有可能造成conflict (就像merge的conflict一樣) 有點討厭
另外 切換到remote branch是可以的 你的用法沒有錯
不過要特別注意不能在remote branch上commit
一定要用local branch去merge他之後 才能commit
最後透過push才能把revision放到remote branch上
--
抱歉中英文夾雜的很嚴重...主要是git裡面的名詞我會用英文這樣....orz
--
: 分支的切換是只能local端嗎?
: git branch -r
: octopress/HEAD -> octopress/master
: octopress/configuration
: octopress/edge
: octopress/gh-pages
: octopress/master
: octopress/move_rakefile_configs
: octopress/rake_minify_js
: octopress/refactor_code_highlight
: octopress/refactor_deployment
: octopress/refactor_js
: octopress/rubygemcli
: octopress/site
: octopress/site-deploy-test
: octopress/subdir
: octopress/thor
: 假設我要切到 octopress/configuration 分支
: git checkout octopress/configuration
: 出現下面錯誤?
: error: You have local changes to 'Rakefile'; cannot switch branches.
: 還有 用 git clone 下載是預設下載遠端的 master的檔案嗎?
: 要如何下載分支的檔案?
: 謝謝
你的問題其實不在於是不是local端 而是因為你Rakefile有改過(local changes)
而你checkout其他branch的話 可能造成你這個修改不見
為了安全起見 git不允許你切換branch
想解決這個問題 你可以先commit local changes 這樣你的working copy就是clean的
不過通常不要為了暫時的切換亂commit比較好 有個好作法是利用 git stash
他會暫時把你現在的working copy存下來 然後讓working copy變成跟HEAD一樣
也就是clean的 你可以stash很多很多working copy 像stack一樣一個個疊上去
等你暫時要做的事情結束後 切回原來branch 再用 git stash pop把剛剛暫存的東西
復原回來就好了~
要注意你如果在HEAD=A的時候stash 然後在HEAD=B的時候pop
有可能造成conflict (就像merge的conflict一樣) 有點討厭
另外 切換到remote branch是可以的 你的用法沒有錯
不過要特別注意不能在remote branch上commit
一定要用local branch去merge他之後 才能commit
最後透過push才能把revision放到remote branch上
--
抱歉中英文夾雜的很嚴重...主要是git裡面的名詞我會用英文這樣....orz
--
Tags:
Linux
All Comments

By Necoo
at 2012-02-06T03:26
at 2012-02-06T03:26

By Eartha
at 2012-02-09T04:26
at 2012-02-09T04:26

By Lauren
at 2012-02-12T04:31
at 2012-02-12T04:31

By Lydia
at 2012-02-16T05:09
at 2012-02-16T05:09

By Isabella
at 2012-02-17T00:00
at 2012-02-17T00:00

By Dinah
at 2012-02-20T00:58
at 2012-02-20T00:58

By Carol
at 2012-02-22T10:01
at 2012-02-22T10:01

By Lily
at 2012-02-26T18:29
at 2012-02-26T18:29

By Harry
at 2012-02-27T17:46
at 2012-02-27T17:46

By Gary
at 2012-02-29T12:56
at 2012-02-29T12:56

By Ingrid
at 2012-02-29T20:18
at 2012-02-29T20:18
Related Posts
使用Xmanager連Centos6.X

By Quanna
at 2012-02-02T16:11
at 2012-02-02T16:11
xrdp 如何共享同一個session?

By Quintina
at 2012-02-02T16:07
at 2012-02-02T16:07
crontab空白?

By Michael
at 2012-02-02T13:51
at 2012-02-02T13:51
請教一個印表機分享的網域問題

By Ophelia
at 2012-02-02T09:54
at 2012-02-02T09:54
centOS 執行 man date

By Hedda
at 2012-02-01T22:41
at 2012-02-01T22:41