2012-07-22 83 views
20

Git包含set of tools contributed by third parties。我不知道我應該如何正確使用這些工具。例如,我想使用git-subtree。似乎有多種方式,我可以用這個:如何在git的contrib目錄中正確安裝工具?

  1. 複製到我的路徑

    cp /path/to/git-subtree.sh /usr/local/bin/git-subtree 
    chmod +x /usr/local/bin/git-subtree 
    

    工作正常,感覺有點哈克。

  2. 符號鏈接到我的路徑

    chmod +x /path/to/git-subtree.sh 
    ln -s /path/to/git-subtree.sh /usr/local/bin/git-subtree 
    

    同樣的作品,感覺稍微少哈克

  3. 使用Git的別名

    以下內容添加到我的全球的.gitconfig文件:

    [alias] 
        subtree = !/path/to/git-subtree.sh 
    

    那麼好老搭配chmod再次:

    chmod +x /path/to/git-subtree.sh 
    

    作品,感覺所有尼斯和git-ISH。

  4. 使用Makefile

    INSTALL file

    cd /path/to/git-subtree.sh 
    make 
    make install 
    make install-doc 
    

    對我不起作用,它會嘗試安裝到不存在的路徑。也許這是因爲我使用homebrew安裝git而不是從源代碼安裝?我懶得去調查;我已經有三種工作選擇。 :)

所以我的問題是,哪些是安裝git-contrib附加組件的首選方式?有沒有更好的方法?我還沒有提出另一個選擇,比上面列出的更好嗎?

+0

你也可以將你的'PATH'變量指向git-contrib的東西。 – pmr 2012-07-23 13:33:22

回答

4

Contribs是一個有用的東西的集合。你不把它們作爲一個包安裝。例如,要安裝選項卡完成,只需從.bash_profile腳本獲取該腳本即可。該文件夾中的每個貢獻都有它自己的使用方式。

爲您從源

make 
sudo make install 

編譯混帳安裝所有的先決條件。

+0

感謝亞當,這很有道理。沒關係,我知道如何從源代碼安裝git,我只是懶得去做。 :) – 2012-07-22 20:17:48

+0

這很簡單,懶惰是沒有藉口的! :P – 2012-07-22 21:25:41

+9

太懶了......;) – 2012-07-22 21:26:32

10

從GIT中/了contrib/GIT-子樹:

如何安裝GIT-子樹
======================= ===

首先,從頂級源代碼目錄構建。

然後,在contrib請/子樹,運行:

make 
make install 
make install-doc 

如果使用配置做主構建git的子樹的構建將 拿起這些設置。如果沒有,你可能將不得不爲前綴提供 值:

make prefix=<some dir> 
make prefix=<some dir> install 
make prefix=<some dir> install-doc 

運行測試第一個副本混帳子樹主構建區域所以 新建的git可以找到它:

cp git-subtree ../.. 

然後:

make test 

我只是驗證了這個工程:

    通過現有的git
  1. 下載源
  2. 安裝建設的DEP

    $ apt-get install libcurl4-gnutls-dev libexpat1-dev gettext libz-dev libssl-dev 
    
  3. 查看最新發布分支,並建立

    $ git co v1.7.11.3 
    $ make prefix=/usr/local all 
    $ sudo make prefix=/usr/local install 
    
  4. 構建和安裝的contrib /子樹

    $ cd contrib/subtree 
    $ make 
    $ make install 
    $ make install-doc 
    
  5. 驗證這一切工作

    /usr/local/bin/git 
    [[email protected] subtree ((v1.7.11.3))]$ git --version 
    git version 1.7.11.3 
    

檢查,我們有最新的飯桶。

[[email protected] subtree ((v1.7.11.3))]$ git subtree 
usage: git subtree add --prefix=<prefix> <commit> 
    or: git subtree merge --prefix=<prefix> <commit> 
    or: git subtree pull --prefix=<prefix> <repository> <refspec...> 
    or: git subtree push --prefix=<prefix> <repository> <refspec...> 
    or: git subtree split --prefix=<prefix> <commit...> 

    -h, --help   show the help 
    -q     quiet 
    -d     show debug messages 
    -P, --prefix ...  the name of the subdir to split out 
    -m, --message ...  use the given message as the commit message for the merge commit 

options for 'split' 
    --annotate ...  add a prefix to commit message of new commits 
    -b, --branch ...  create a new branch from the split subtree 
    --ignore-joins  ignore prior --rejoin commits 
    --onto ...   try connecting new tree to an existing one 
    --rejoin    merge the new branch back into HEAD 

options for 'add', 'merge', 'pull' and 'push' 
    --squash    merge subtree changes as a single commit 

檢查,我們有子樹工作。

+2

它的工作原理!謝謝。這是關鍵:'make prefix =/usr/local all' ..我之前做過一個香草使得安裝git和子樹安裝失敗。一個小的省略:當爲子樹執行'make install-doc'時,我錯過了一個額外的依賴'asciidoc'。 – Anentropic 2012-08-07 11:47:27

+0

另外,當沒有閱讀你對安裝過程的描述時,從git文檔中不清楚是否在git項目之前安裝和構建子樹contrib項目。 – Henrik 2012-08-22 14:03:47

+0

我很困惑。如果你已經安裝了(最新版本的)git,爲什麼你需要從頭開始編譯來使用contribs中的某些東西? – 2012-12-13 09:55:31

0

下面所有的在一個命令,在Ubuntu只測試:

curl -L https://raw.github.com/gist/3426227 | bash 

現在,這裏是如何使用Git作爲一個整體在Ubuntu安裝最新的git

要做到這一點作爲一個包(如下所示:

sudo apt-get remove git -y 
sudo apt-get install libcurl4-gnutls-dev libexpat1-dev gettext libz-dev libssl-dev asciidoc 

如果您沒有安裝asciidoc,請忽略make target'install-doc'下面的行。

這將簽出主標籤/最新標籤發行版,並將其與checkinstall一起安裝爲一個包。

git clone https://github.com/git/git.git 
cd git 
make prefix=/usr/local all 
sudo checkinstall --pkgname=git make prefix=/usr/local install 

那麼的contrib:

cd contrib/subtree 
make prefix=/usr/local 
sudo checkinstall --pkgname=git-subtree make prefix=/usr/local install 

...回答yesy的問題是否將文件從主文件夾排除。

sudo checkinstall --pkgname=git-subtree-doc make prefix=/usr/local install-doc 

...回答yesy的問題是否將文件從主文件夾排除。

您現在可以處理的git包:

dpkg -r git 

和子樹包:

dpkg -r git-subtree 
dpkg -r git-subtree-doc 

如果你不喜歡有乳膠Perl腳本億字節後佔用硬盤空間:

sudo apt-get remove asciidoc -y 
sudo apt-get autoremove -y 

或者所有這一切(所有構建階段)

sudo apt-get remove -y libcurl4-gnutls-dev libexpat1-dev gettext libz-dev libssl-dev asciidoc 
sudo apt-get autoremove -y 

感謝@託德爲我需要的基本命令!我不能讓git subtree --help查找正確的手冊頁。

+0

這種方法導致了git-man,git-core和gitk包的問題,​​並且無法在沒有將git升級到舊版本的情況下安裝git-cola。 – itsadok 2012-11-26 07:52:26

+0

我也有問題。如果您有解決方案,我很樂意更新這篇文章。 – Henrik 2012-11-26 17:38:46

+0

首先,您需要在指令的開頭添加'apt-get remove git-man'。然後,我想用checkinstall提供假git-man,git-core和gitk包會改善問題。您可能需要指定足夠高的版本號來檢查安裝,以防止「升級」軟件包。在嘗試所有這些之前,我放棄了,最終做了我的回答。 – itsadok 2012-11-27 09:40:00

8

下面是爲我工作,在Ubuntu 12.10安裝git的子樹的最簡單的事情:

獲取代碼

git clone https://github.com/git/git.git --depth=1 
cd git/contrib/subtree 
make 

「安裝」 入混帳tools目錄

sudo cp git-subtree /usr/lib/git-core/ 

對於手冊頁,你需要asciidoc這不是一個小的安裝,但如果你有它:

make doc 
gzip git-subtree.1 
sudo cp git-subtree.1.gz /usr/share/man/man1 

就是這樣。

+0

工程就像一個魅力(至少在Ubuntu上)。簡單得多,只要你已經安裝了git - 無需從源代碼中「make」和「make install」整個git。另外 - 很高興有一個手冊頁! – Timur 2013-10-18 14:12:42

2

所有這一切看起來更復雜一點比必要的..
(也許是因爲install.sh是最近才加入?)
這是我工作。或者看起來如此。

# go to a directory where it's ok to put temporary stuff 
cd ~ 
git clone git://github.com/apenwarr/git-subtree.git 
cd git-subtree/ 
# shell script does the job for you. 
sudo sh ./install.sh 
cd .. 
# remove the git cloned stuff, now that all relevant things have been copied (we hope) 
rm -r git-subtree 

# test that it works 
git subtree 
# should print some help/usage stuff. 

有說法大多隻是一條指令:
https://github.com/apenwarr/git-subtree/blob/master/INSTALL

我比這更傻一點。我需要告訴我,在我運行shell腳本之前,我必須將(git clone)下載到任意位置,並且這些東西可以在之後處理。

安裝的內容。sh很有啓發,
https://github.com/apenwarr/git-subtree/blob/master/install.sh
如果你想安裝一個不提供自己的install.sh的git thingie,這可能是一個開始的地方。

+0

我的答案可能是愚蠢的關於此.. https://github.com/apenwarr/git-subtree/blob/master/THIS-REPO-IS-OBSOLETE – donquixote 2013-02-28 23:38:17

+0

它似乎是最新的git,這是可用的(1.7.11 )並不容易在Debian上使用。你用apt-get得到的最新版本是1.7.10。所以這個回購可能不是沒有意義的。 – donquixote 2013-03-01 00:00:57

+0

在我看來,這是一個不錯的主意,前提是我沒有找到任何其他標準Windows Git Bash的解決方案,這個解決方案沒有製作。使用'cp git-subtree.sh「來安裝它$(git --exec-path)」/ git-subtree'似乎工作正常。 – Timur 2013-10-18 14:15:52