Re: [問題] git 分支使用疑問
※ 引述《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
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 218.165.96.114
※ 編輯: CrBoy 來自: 218.165.96.114 (02/03 00:55)
推
02/03 10:34, , 1F
02/03 10:34, 1F
→
02/03 16:54, , 2F
02/03 16:54, 2F
→
02/03 16:54, , 3F
02/03 16:54, 3F
推
02/06 02:58, , 4F
02/06 02:58, 4F
→
02/06 02:59, , 5F
02/06 02:59, 5F
→
02/06 03:02, , 6F
02/06 03:02, 6F
→
02/06 03:02, , 7F
02/06 03:02, 7F
推
02/06 03:08, , 8F
02/06 03:08, 8F
→
02/06 03:09, , 9F
02/06 03:09, 9F
→
02/06 03:11, , 10F
02/06 03:11, 10F
→
02/06 03:12, , 11F
02/06 03:12, 11F
→
04/07 17:43, , 12F
04/07 17:43, 12F
→
04/07 17:44, , 13F
04/07 17:44, 13F