2013-12-09 59 views
0

是否有一種簡單的方法可以在不輸入長分支名稱的情況下在分支之間切換?我大概可以用散列來引用分支中的最新提交。但是如何在檢出另一個分支時獲得散列?在Git中長名稱的分支之間切換

我想這樣做:

> git branch -a 
master ab12cd... 
feature/separate-sound-channels 34efgh... 
> git checkout 34efgh 

回答

1

你不能簡單地籤哈希,因爲雖然會得到正確的提交,就會把你「分離的頭」的狀態,這基本上意味着你的工作拷貝不與特定分支相關聯,所以移動分支標籤的git命令將不知道要影響哪個分支。

正如@約翰Zwinck提到,git-completion.bash將執行頭完成(等細節)當你輸入一個git命令,按下tab鍵時,頭名(分行或標籤)下一個被在命令行預計:

http://git-scm.com/book/en/Git-Basics-Tips-and-Tricks#Auto-Completion

mouse:~/Documents/workspace/jackson-core (master) $ git branch -a 
* master 
    temp 
    remotes/origin/2.0 
... 
mouse:~/Documents/workspace/jackson-core (master) $ git tag 
2.1.0b 
2.1.1b 
jackson-core-2.0.0 
jackson-core-2.0.0-RC1 
... 
mouse:~/Documents/workspace/jackson-core (master) $ git checkout <tab> 
2.0      jackson-core-2.0.0-RC3 jackson-core-2.2.1 
2.1      jackson-core-2.0.1  jackson-core-2.2.2 
2.1.0b     jackson-core-2.0.2  master 
2.1.1b     jackson-core-2.0.4  origin/2.0 
2.2      jackson-core-2.0.5  origin/2.1 
FETCH_HEAD    jackson-core-2.0.6  origin/2.2 
HEAD      jackson-core-2.1.2  origin/HEAD 
ORIG_HEAD    jackson-core-2.1.3  origin/gh-pages 
gh-pages     jackson-core-2.1.4  origin/master 
jackson-core-2.0.0  jackson-core-2.1.5  temp 
jackson-core-2.0.0-RC1 jackson-core-2.2.0-rc1 
jackson-core-2.0.0-RC2 jackson-core-2.2.0b 
mouse:~/Documents/workspace/jackson-core (master) $ git checkout 2.<tab> 
2.0  2.1  2.1.0b 2.1.1b 2.2