顯示具有 git 標籤的文章。 顯示所有文章
顯示具有 git 標籤的文章。 顯示所有文章

2025年11月14日 星期五

[git]git 推到別站

 # 假設你已經從 A 站 clone 下來,這時 origin 指向 A 站

git remote rename origin upstream

# 新增 B 站的遠端儲存庫

git remote add origin [B 站的 Repository URL]

# 之後你就可以 push 到 B 站了

git push -u origin main

# 如果需要,也可以從 A 站拉取更新

git pull upstream main

2019年1月6日 星期日

[git] 不想一直輸入帳號密碼

如果每次跟遠端更新都要輸入密碼,有好處就是讓自己不會忘記密碼,但是有時要全部專案同時更新備份下來,寫了個批次檔來做這事,卻會停下來一個個輸入密碼就很討厭。這時候就加上一個設定,就可以讓輸入過的密碼自己記下來省掉麻煩。

在 windows 這裡要這樣設定:

git config --global credential.helper wincred
關於 timeout 的設定就沒有看到了。

2018年8月1日 星期三

[git]用工具的還是人

一則臉書貼文,有關 git 之前大家怎麼版控的。
https://www.facebook.com/groups/git.tw/permalink/1817171478331512/
樓主留言問到:「想請教一下各位前輩
知道在沒有git 或 svn之類的軟體出現之前
是怎麼協同開發的...

剛剛跟公司的高層主管(不會寫程式)聊天
他說我們公司DevOps很奇怪
為什麼都沒辦法協同開發
說到協同開發每個人都一臉大便

我跟他說很多點公司的現況
1.git當備份工具 commit都沒有意義 更別說開分支之類的
2.大家都是直接連到伺服器去改程式
3.沒有人來負責merge程式
之類的

就被他反嗆
他們1X年前沒用這些東西
大家也都是連到同一台伺服器去做
照樣都可以協同開發
系統也更新了好幾代
為什麼現在不行...
所以想了解一下早期1X年以前
git svn這些東西出現以前
是怎麼協同開發的」

結果有滿多留言不是在回答「git svn這些東西出現以前
是怎麼協同開發的」,而是在講主管有問題。
如果是你,應該怎麼回答這問題呢?

也許樓主是來討拍的,而講主管有問題的才是正確解答。
但我還是留言以前經歷過的協同開發怎麼做的:「Code review, 專人merge 。之後有rational, source safe, cvs,就有辦法一個人改的時侯check out鎖檔不讓別人改,改完check in。」

當然,有些人講得沒錯,現在的程式複雜度比較高,沒有工具就很難處理好。
可以說,因為現在工具的存在,才會出現現在程式的高複雜度。
但反過來說也對,因為有高複雜度的程式的需求,才會造成現在工具的誕生。
但是,重要的還是,不會用工具的人還是會搞得一團糟。
人的概念、程式複雜度、工具支援度,三個東西是程度相合的。其中一個跟不上,就必定出問題,就必定要調整。

最後,我只能留以下留言給事主:
「如果你推不動其他資深同事,那就跟老闆說清楚。
你講的123點,不論用什麼工具都是必須要人們去做好的。
工具再好,人亂用,還是一塌糊塗。
用工具卡死、強迫一定要做到123點,每個 commit 要送老闆簽核、只有某些人才有辦法 merge 進版…等都有辦法做到,以前的幾個 source control software 都做得到。但是如此做會面對更多人性的挑戰,因為那是用伺服器就開始卡權限的,一個人不在位子上,就有可能整個公司不用改程式,一定更多人會抱怨。
工具會進步,就代表舊的方式需要捨棄一些東西來換取另一些東西。git 就是捨棄嚴格卡控,換來靈活合併與分支。如果同事們沒有相對應的概念,就容易弄得更亂。
這時候你們要想想該選擇哪種合作模式才是適合你們這群人,看是要改模式還是換工具或是換公司。」

以上幾點感想。

2018年4月3日 星期二

[git]form hg to git (windows)

目前主要趨勢底定是 git。得要先把 hg 的專案轉到 git 來。

我在 windows 有裝 tortoisehg,所以作法如下:

(1) 在 tortoisehg 的 global settings 裡,把 extension hggit 打開。
(2) 在 bitbucket 開一個 git repo。假設路徑為 https://bitbucket.org/username/hg-projectname-git
(3) 在原來的 hg 的目錄下,執行以下命令,產生 git 的頭:
hg bookmark -r default master
(4)  在原來的 hg 的目錄下,執行以下命令,把歷史推上去:
hg push git+https://bitbucket.org/username/hg-projectname-git
(5) 用 git clone 新路徑。之後就用這個新的 git clone 目錄工作。

打完收工

注意事項:

(1) tortoiseplink 已經失效,所以 hg push git+ssh 這個指令會失敗。我找不到辦法換成 ssh.exe,所以就用 https 的方式。
(2) hg push 的路徑不要用 https://username@bitbucket.org 這種,hg 會產生 getaddrinfo 錯誤。



主要參考文章三篇:
http://arr.gr/blog/2011/10/bitbucket-converting-hg-repositories-to-git/

https://mcmblog.azurewebsites.net/using-tortoisehg-with-git/

https://stackoverflow.com/questions/9272233/hg-clone-using-mercurial-throws-getaddrinfo-failed-error-windows-7

2017年3月1日 星期三

[超譯]git 七招打天下

原文連結:
http://www.infoworld.com/article/3169942/application-development/7-simple-commands-for-git-survival.html

You don’t have to get fancy to get most of your work done with Git; start with these essential commands
用 git 工作你不需要趕流行用什麼特技,只要用這些基本指令就好。

大多數公司都用 git,不只為了開發商業或消費性 app。科學與政府組織也有好理由,所以這些技術越來越常被使用。

git 允許漸進式合作,快速散佈,為程式碼建立信心,三個都是很重要的目標,所以很多團隊納為 devops 的手法。為了要達成這些目標,許多 git 平台包含整合工具支援程式碼測試與團隊管理。

就算 git 變得無所不在,仍有一些在觀望。 GitLab 最近有個調查,發現 40% 的開發團隊憂心 git 的學習曲線。自然地,在 GitLab,我每天用它工作,我了解 git 對新使用者的挑戰。

幸運的是,有大量的資源可以幫助新使用者克服他們的焦慮。許多公司,包含我們自己,都有免費資源給想要學習的開發者。除了公司主導的資源外,git 也有很多社群技援,分享許多常見問題的解法。

保持簡單

要了解 git,最好要知道它是從命令列來的。但是,有經驗的 git 使用者喜歡客戶端有簡易介面讓易用性提高。Git Tower 與 Tortoise Git 就是非常好的客戶端程式。

好消息是,多數開發者可以只學幾個基本指令就可以處理大多數的工作。與 repo 同步、建立新分支、建立新增與提交,把改變推回遠端等,這幾個工作,使用以下會提到的七個命令就可以做到。git 不需要搞得太複雜。

切換到主分支

git checkout master

這個 git checkout 讓你在分支間移動,並回復檔案。git checkout master 會切換到主線,這是你要改東西之前最好的出發點。

拿到最近的更新

git pull origin master

一但你切到主線,你可以用 git pull origin master 保證你的分支裡的東西是repo的裡最新的。這是通常在合併上游改變之後要做的事。git pull實際上是合併了git fetch(這是把最後資訊抓回來) 與git merge(這把兩個歷史合併)這兩個命令。基本上,git pull origin master讓你一次做兩個命令,這非常省時間。

在一個 repo 開始工作前,執行一次 git pull origin master 是個好主意。畢竟,在協作過程中,你會想要確定你的 repo 跟遠端最新的是一樣的內容。

擴展你的分支

git checkout -b branchname

這個命令用來建立新的分支,分支名是 “branchname”,然後移動過去。

分支是 git 的基礎功能。想要開個新功能嗎?輸入git checkout -b new-feature,建立一個新分支叫做”new-feature”,然後開啟它。這個新分支讓你平行開發,與你的同事之間是一個,你自己是另一個分支,程式碼分開,不會互相干擾。

當你準備好要分享你的工作成果,你可以把分支推去遠端或是合併到新分支(通常是主線),這些指令馬上來說明…。

當你需要知道狀況

git status

讓 git 告訴你現在你的 repo 的狀況。例如,git 會指出哪些檔案有改變過或是你的分支新增的。然後 git 會給予建議該怎麼做,提供指令如何 stage 或 commit 這些檔案。

為了下一步準備

git add

這個指令會在工作目錄加入一個改變,使得它放到台面(也就是標記為改變的一部份)。這個改變可以是移除或新增一個檔案或目錄。這是提交改變的準備步驟。實際的動作已經做完了,但這個命令只是正式申明這些改變要被提交。

如果你對所有改變都很滿意,你可以加上 -all選項,git add -all會標明所有這個工作目錄與子目錄的改變,包含目錄的移除。

記錄你的改變

git commit

這個命令會記下你的改變,放在本地端 repo。不要與git push搞混,接下來會解釋。你也可以使用git commit刪除檔案,用些迂迴的方式來做。

git 是個整包的提交,也就是說提交是個改變(裡面會包含此次所有的新增、刪除、更新)。git commit 會把之前用git add記為改變的提交出去。這個改變是記在本地 repo。要分享出去就一定要推到遠端。

分享你的改變

git push

執行這個命令會推送你的改變到遠端,有數個方式你可以調整。單純git push這個指令,會改變 repo 與它的所有相關。

git push <remote> <branchname> 這指令會推送本地端 的改變到,它通常是你協作同事的伺服器。預設,第一個 remote 叫做 “origin”,如果你在 “new-feature” 分支有改變,你可以下 git push origin new-feature,把改變(提交)送到你協作同事的地方。

你完全可以用以上的指令把 git 相關工作搞定。通常開發者會遇到困難是因為他們想用複雜指令像是git rebase而把事情搞得太複雜,而導致不清楚自己在做什麼以及是否有必要搞這些。

當有疑問的時候,執行git status,讓 git 告訴你。

2016年7月28日 星期四

[超譯] 核心版控演義

linux 核心的版本控制管理系統,曾經有經歷過一段動盪,linus 自己曾經在郵件列表裡回過一段文章,提出自己的看法。郵件標題是 「Kernel SCM saga..」
原文連結:
http://lkml.iu.edu/hypermail/linux/kernel/0504.0/1540.html

好,有很多人已經發現(有些人已經知道好幾個星期),我們正努力解決這一兩個月與 BK [譯註:BitKeeper] 之間的衝突。但,我們沒有成功,所以,核心組正在尋找替代方案。
(顯然這訊息會到 slashdot,所以應該 每個人都知道 )
我選了 BK 就讓能衝突消失的期待,似乎沒有成功 ( “你沒看見這幾G又幾G 的火熖嗎?”)。所以,在某種意義上是無法避免的。但我確信我曾希望能有合理的開源替代能選擇,為此,我們將必須忙和一陣子。
題外話,別怪 BitMover,就算這是一個常見的反應。Larry 真的是想把事情做好,但事情到了我不想要的地步,想要把兩塊湊在一起需要的膠水越多越好。
我們已經使用 BK 三年了,事實上,現在最大的問題是有許多人用過最好的工具之後,變得非常挑剔。包含我自己,我們都因為 BitKeeper 的幫助,在 merging 我的 tree,或把他們的 tree 傳給我的時候變得比較輕鬆。
當然,也許更大多數的人只是把 BK 當成更好(也更快)的「匿名 CVS」的客端。眼前的問題是我花了許多時間試圖找到最好的協作方案。
注意,BitKeeper 不是消失了。只是現在最真切的事情是,我決定不再使用 BK,主要因為我需要找到替代,而不是「讓東西持續正常」。我決定硬著頭皮,看看沒有 BK 的生活會是怎樣。到目前為止,是個黑白的世界。
不要過度解釋,我會用個星期閉關,(想做是 linus 只是去放假的正常事件),我也正在找人負責維護 BK tree,至少是能夠傳給我(單獨)補丁,我會自己 想辦法 merge。
所謂「單獨補丁 individual patches」是個關鍵字。題外話,BK 一個做得很好的事,許多人就算沒用 BK 也喜歡的,就是它對於改變的視圖很棒。這個不會消失。
事實上,BK 讓我們做事的方法有了根本的改變。像是 changeset 的視圖、讓我能相信子維護者能做更大的事、不用按順序上補丁…等。所以三年的 BK 使用不是浪費。我相信這會讓我們用更好的方式做事。我會尋找讓這些事情繼續的方法。
所以,我只是要說,我個人與 BK 相處愉快,與 Larry 也是。合作沒有成功讓核心開發有了巨大的困難。一個暫時性的問題,要產出在 BK 允許的範圍內使用的工具,這一點我們會繼續努力。
讓火開始燒吧。
Linus
PS. 不要再跟我說 subversion。如果你一定要,去研究 “monotone”,那看來是最可行的。但不要再煩開發者讓他們無法把事情做完。他們已經要煩惱我的問題了。

[閒聊]超簡單回答 - 什麼是 github?

github 是一個程式碼代管網站,它讓你可以放程式碼供大家下載。由於它使用 git 版本控制程式,所以名字 github 裡面有個 git。

git 是由 linus 開發出來的(第一版)。是為了因應分散式開發的特性而另外開發的。在他開發的時候,同時間也有其他的分散式開的版本控制系統已經出現,BitKeeper,或是 Mercurial。Mercurial 開發時間只有晚 git 一些些而已。但是 linus 覺得都不合他的意,所以就自幹一套,然後把 linux kernel 的版本控制系統換成了 git。

另外一提,Mercurial,俗稱 hg,這一套版本控制系統是用 python 寫的,Mozilla 與 python 都將程式碼轉移到 hg 的系統之中。

我想,如果有人問我要選哪一個?因為現在使用 git 的人多,也許學用 git 會比較好。至於我自己個人,已經用了 hg,現在還不想隨便換。

參考:
https://zh.wikipedia.org/wiki/Git
https://git-scm.com/book/zh-tw/v1/%E9%96%8B%E5%A7%8B-%E9%97%9C%E6%96%BC%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6
http://lkml.iu.edu/hypermail/linux/kernel/0504.0/1540.html

2015年11月3日 星期二

2013年7月18日 星期四

[git][dulwich]在 windows 才會有的權限認定問題

前一陣子試著使用 dulwich 來操作 .git 裡面的資料,例如上傳到 changeset 到 remote、下載 changeset 到 local。看起來都很正常。但是,把檔案從 .git 裡面拿出來放,就會判定某些檔案被改變,我去檢查內容,自己使用 sha,md5 對兩個檔案檢查,結果顯示兩個檔案內容完全一樣。我想,dulwich 這麼多人用,難道我又遇到「沒人會遇到」的問題嗎?

另外我使用 tortoisegit 來檢查其內容,一樣也是說相同,但是用 dulwich 拉回來的 .git,跟 tortoisegit 拉回來的 .git 對於相同檔案,卻是一個說相同,一個說有改變。這可搞死我了,難道要放棄使用 dulwich 嗎?

後來翻到一個舊的 tortoisegit 的 issue:https://code.google.com/p/tortoisegit/issues/detail?id=812

Allow to change git file permission mask / attributes (especially executable bit)

才知道,dulwich 可能也是中同一個招數。git 是有檢查 Read, Write, Execute vs User, Group, Other 的。於是就可以解釋,為何只要是 script 或是 linux 的執行檔才會出現內容相同,但被判定有改變。在 windows 的檔案權限是 666,跟原來的不一樣了,也沒辦法改成 755。不曉得 tortoisegit 怎麼解決這問題的…。我這裡暫時停止研究了。

[git]學習 TortoiseGit - revert

原本有在用 hg,還以為會很順利地就會使用 git。

結果,等到真正開始管專案,第一個遇到的就是,revert 呢?

因為原本很習慣地,只要有臨時改過某個檔,要回到原狀,就很簡單地「指」著那個檔按右鍵,選revert

image

在下圖按下 revert 就解決了。

image 

但是,在 tortoisegit 我眼花啦~~~~~!!

我找了兩天啊!可說是上天下海用 google 去找,怎麼沒有人會有這種問題呢?

大概沒有人跟我一樣眼睛被蚵仔擋到,就在這兒啊,怎麼會有人要問這種問題呢?

image

其實還真有…

http://stackoverflow.com/questions/8011538/git-pulling-only-certain-files

2013年6月6日 星期四

[python]dulwich 只是個 git client 我想…

https://github.com/jelmer/dulwich

安裝…找不到說明,BUT!

出奇的簡單,用 git 從 github 下載回來,使用 setup.py install 就搞定。

 

操作…

操作的文件在這 http://www.samba.org/~jelmer/dulwich/docs/tutorial/index.html,真的是RTFM,不注意還找不到文件在哪裡。我太嫩了。

已經知道細節的人,可以直接跳 http://www.samba.org/~jelmer/dulwich/docs/tutorial/repo.html 開始!但是,不知道細節的人,一定要從頭到尾看清楚每個字,尤其是 Introduction,它把這個軟體的功能說的很清楚。就是「它有寫的就是它能做的」。我原先以為他能像 git command line 工具一樣操作,結果不是。文章中,介紹了 .git 裡面的三個物件,commit, tree, blob,dulwich 軟體主要就是讓你操作這三個物件來達成你想要的動作。於是經過了嘗試、失敗、掙扎、又嘗試別的程式,失敗,掙扎,又回來嘗試這程式…的循環,我得到了我想要的結果。

我這裡整理一下我知道的跟我不知道的對應表。
















git init myrepo
from dulwich.repo import Repo
repo = Repo.init('myrepo',mkdri=True)
git --bare init不知道該怎辦。因為我只是把 dulwich 當 client 端,應該不會用到這個指令。
git add foo.txtrepo.stage(["foo.txt"])
git commitcommit_id = repo.do_commit("The first commit", committer="your name <name@example.com>")
git clone說明:這個大家最常用來抓新專案的指令,沒辦法直接對應,要先使用 fetch,再自行把檔案內容從 stores 裡面抓出來,寫到本地端的檔案系統。
例:

repo = Repo("myrepo")
commit_sha = repo['HEAD'].id  # 先拿到最近的 commit sha
tree = repo[commit_sha].tree    # 再拿到那個 commit 的 tree
store = repo.object_store
for filename, mode, sha in store.iter_tree_contents(tree): # 列舉那個 tree 的全部內容
    relpath = unicode(os.path.join(repo.path,filename))    # 計算出本地端的相對路徑
    ensure_dir_exists(os.path.dirname(relpath))               # 確定目錄有建立
    with open(relpath,'wb') as f:                                    # 開啟 bin mode 寫入內容
        f.write(repo[sha].data) 
    repo.stage([filename,])
    os.chmod(relpath, mode)


這是我不小心在亂晃的時候發現的 https://lists.launchpad.net/dulwich-users/msg00116.html 藏得很隱密

git fetch目前到 github 我都是用 https:// 的,所以就試了一個用 https:// 的。git:// 的我沒試。
server_address = 'https://github.com/'
client = HttpGitClient(server_address)
local = Repo.init("local", mkdir=True)
remote_refs = client.fetch("/jelmer/dulwich.git", local, determine_wants=local.object_store.determine_wants_all, progress=sys.stdout.write)
local["HEAD"] = remote_refs["HEAD"] #這個很重要,不然會沒有HEAD!

2013年6月4日 星期二

[nodejs]在 windows 安裝 git-server 有奇怪事件發生(已解決)

https://github.com/qrpike/NodeJS-Git-Server

在照該網站上的步驟進行,到了要用 git 測試,就會出現

events.js:72
throw er; // Unhandled 'error' event
^
Error: spawn ENOENT
at errnoException (child_process.js:980:11)
at Process.ChildProcess._handle.onexit (child_process.js:771:34)

不曉得為什麼,已經在那裡留 issue 了。

但是在 ubuntu 就沒問題…。

後續:

後來不死心,用了最笨的方法,就是在 source code 裡到處加 console.log,看看程式怎麼跑。

後來知道了兩點,就把它修好了。

一、啟動新 server 需要指定 repoLocation。因為預設是 /tmp/repo,這目錄在 windows 下一定不存在。

二、git-server 其實是執行 git 指令,所以,一定要安裝 git,以 windows 來說,我安裝了 msysgit 的 Git-1.8.1.2-preview20130201.exe。

三、git-server 其實是執行 git 指令,又不會自帶路徑,所以要在環境變數 path,加入以下路徑:

C:\Program Files (x86)\Git\bin;C:\Program Files (x86)\Git\libexec\git-core

這樣,就可以啟動 git-server 了。

2013年5月27日 星期一

[nodejs] 安裝 node-gitteh 失敗過程

因為有人說,因為大家都是 *nix like,只有 windows 不是,所以有問題會很慢才解決,我當場就把作業系統給換成 ubuntu。

gitteh 是一個讓 nodejs 可以用程式的方式來執行 git 指令,因為我想要自動偵測新檔案出現,就自動 commit,所以腦筋就動到這東西來了。也有人說,只要會用 shell 指令,把 stdout 導出來,再做一些文字解析的工作,也就完成一樣的事,不過,就是怕改版文字會跑掉。所以,有人就寫了 libgit2 的 C 語言函式庫讓人使用,再由各語言呼叫 C 函式庫來滿足大家的需求,例如 nodejs、python。而 nodejs 的 bindings 就叫做 gitteh。

libgit2 的網站 http://libgit2.github.com/

gitteh 的網站 https://github.com/libgit2/node-gitteh

安裝 gitteh (在 ubuntu)

在 github 這裡,就只有說 npm  install gitteh 就好,看了就很高興。

BUT! 人生就怕這個字。

執行 npm install gitteh 遇到

hadoop@ubuntu:~/nodejs/myapp/src$ npm install gitteh
npm http GET https://registry.npmjs.org/gitteh
npm http 304 https://registry.npmjs.org/gitteh

> gitteh@0.1.0 preinstall /home/hadoop/nodejs/myapp/src/node_modules/gitteh
> node-waf configure --use-bundled-libgit2

sh: 1: node-waf: not found
npm ERR! weird error 127
npm ERR! not ok code 0

 

以為是少 node-waf,於是下指令 npm install node-waf

結果

hadoop@ubuntu:~/nodejs/myapp/src$ npm install node-waf
npm http GET https://registry.npmjs.org/node-waf
npm http 404 https://registry.npmjs.org/node-waf
npm ERR! 404 'node-waf' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it
npm ERR! 404
npm ERR! 404 Maybe try 'npm search waf'
npm ERR! 404
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, or http url, or git url.

npm ERR! System Linux 3.5.0-17-generic
npm ERR! command "/home/hadoop/.nvm/v0.10.7/bin/node" "/home/hadoop/.nvm/v0.10.7/bin/npm" "install" "node-waf"
npm ERR! cwd /home/hadoop/nodejs/myapp/src
npm ERR! node -v v0.10.7
npm ERR! npm -v 1.2.21
npm ERR! code E404
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR!     /home/hadoop/nodejs/myapp/src/npm-debug.log
npm ERR! not ok code 0

唉~~

試了 http://stackoverflow.com/questions/13784551/how-to-install-node-gitteh-module-from-npm-nodejs-0-8-x

npm install git://github.com/jmendeth/node-gitteh.git
失敗
再試 https://github.com/libgit2/node-gitteh/issues/21 還是失敗
我想試試先安裝 libgit2,npm install libgit2,結果找不到。
npm search libgit2 有找到一個 nodegit,就來試試,npm install nodegit。
跑了一大串之後得到


> nodegit@0.0.79 install /home/hadoop/nodejs/myapp/src/node_modules/nodegit
> node install.js


[nodegit] Downloading libgit2 dependency.
[nodegit] Building libgit2 dependency.
/usr/bin/env: cmake: No such file or directory
npm ERR! weird error 127
npm ERR! not ok code 0


 


於是 sudo apt-get install cmake 後,再一次,結果換 g++ 找不到。依稀記得有個 build-essential,就裝它吧。 sudo apt-get install build-essential 。再一次安裝 nodegit。好像成功了,雖然有 WARN



npm WARN package.json cli-table@0.2.0 No repository field.
nodegit@0.0.79 node_modules/nodegit
├── async@0.2.8
├── request@2.9.203
├── tar@0.1.17 (inherits@1.0.0, block-stream@0.0.6, fstream@0.1.22)
├── fs-extra@0.6.0 (jsonfile@0.0.1, ncp@0.4.2, mkdirp@0.3.5, rimraf@2.1.4)
└── node-gyp@0.8.5 (which@1.0.5, osenv@0.0.3, graceful-fs@1.2.1, rimraf@2.1.4, semver@1.1.4, mkdirp@0.3.5, glob@3.2.1, fstream@0.1.22, npmlog@0.0.2, nopt@2.1.1, minimatch@0.2.12)


 


又回到執行 npm install gitteh,登登!



> gitteh@0.1.0 preinstall /home/hadoop/nodejs/myapp/src/node_modules/gitteh
> node-waf configure --use-bundled-libgit2


sh: 1: node-waf: not found
npm ERR! weird error 127
npm ERR! not ok code 0


 


此路不通啊。


下載 git clone https://github.com/libgit2/node-gitteh.git 來安裝試試



hadoop@ubuntu:~/nodejs/myapp/src/node-gitteh$ node install.js


module.js:340
    throw err;
          ^
Error: Cannot find module 'async'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/home/hadoop/nodejs/myapp/src/node-gitteh/install.js:1:75)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)


 


看來是 async 找不到,就裝一下,




hadoop@ubuntu:~/nodejs/myapp/src/node-gitteh$ npm install async -g
npm http GET https://registry.npmjs.org/async
npm http 304 https://registry.npmjs.org/async
npm WARN package.json github-url-from-git@1.1.1 No repository field.
npm WARN package.json assert-plus@0.1.2 No repository field.
npm WARN package.json ctype@0.5.2 No repository field.
async@0.2.8 /home/hadoop/.nvm/v0.10.7/lib/node_modules/async


 


再試發現裝到 global 好像沒反應,就改裝在工作目錄。



hadoop@ubuntu:~/nodejs/myapp/src/node-gitteh$ node install.js


module.js:340
    throw err;
          ^
Error: Cannot find module 'async'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/home/hadoop/nodejs/myapp/src/node-gitteh/install.js:1:75)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
hadoop@ubuntu:~/nodejs/myapp/src/node-gitteh$ npm install async
npm http GET https://registry.npmjs.org/async
npm http 304 https://registry.npmjs.org/async
async@0.2.8 node_modules/async


hadoop@ubuntu:~/nodejs/myapp/src/node-gitteh$


npm install async
npm http GET https://registry.npmjs.org/async
npm http 304 https://registry.npmjs.org/async
async@0.2.8 node_modules/asynchadoop@ubuntu:~/nodejs/myapp/src/node-gitteh$
hadoop@ubuntu:~/nodejs/myapp/src/node-gitteh$
hadoop@ubuntu:~/nodejs/myapp/src/node-gitteh$
hadoop@ubuntu:~/nodejs/myapp/src/node-gitteh$
hadoop@ubuntu:~/nodejs/myapp/src/node-gitteh$ node install.js
[gitteh] Downloading libgit2 dependency.
Submodule 'deps/libgit2' (git://github.com/libgit2/libgit2.git) registered for path 'deps/libgit2'
Cloning into 'deps/libgit2'...


中間省略


[gitteh] Building native module.
/bin/sh: 1: ./node_modules/.bin/node-gyp: not found


又少 node-gyp。再來 npm install node-gyp



hadoop@ubuntu:~/nodejs/myapp/src/node-gitteh$ npm install node-gyp
npm http GET https://registry.npmjs.org/node-gyp
npm http 304 https://registry.npmjs.org/node-gyp
npm http GET https://registry.npmjs.org/tar
npm http GET https://registry.npmjs.org/fstream
npm http GET https://registry.npmjs.org/graceful-fs
npm http GET https://registry.npmjs.org/minimatch
npm http GET https://registry.npmjs.org/mkdirp
npm http GET https://registry.npmjs.org/nopt
npm http GET https://registry.npmjs.org/npmlog
npm http GET https://registry.npmjs.org/osenv
npm http GET https://registry.npmjs.org/request
npm http GET https://registry.npmjs.org/rimraf
npm http GET https://registry.npmjs.org/semver
npm http GET https://registry.npmjs.org/which
npm http GET https://registry.npmjs.org/glob
npm http 304 https://registry.npmjs.org/graceful-fs
npm http 304 https://registry.npmjs.org/minimatch
npm http 304 https://registry.npmjs.org/fstream
npm http 304 https://registry.npmjs.org/nopt
npm http 304 https://registry.npmjs.org/npmlog
npm http 304 https://registry.npmjs.org/osenv
npm http 304 https://registry.npmjs.org/request
npm http 200 https://registry.npmjs.org/tar
npm http 304 https://registry.npmjs.org/rimraf
npm http 304 https://registry.npmjs.org/semver
npm http 304 https://registry.npmjs.org/which
npm http 304 https://registry.npmjs.org/glob
npm http 304 https://registry.npmjs.org/mkdirp
npm http GET https://registry.npmjs.org/ansi
npm http GET https://registry.npmjs.org/abbrev
npm http GET https://registry.npmjs.org/lru-cache
npm http GET https://registry.npmjs.org/sigmund
npm http GET https://registry.npmjs.org/inherits
npm http GET https://registry.npmjs.org/inherits
npm http GET https://registry.npmjs.org/inherits
npm http GET https://registry.npmjs.org/block-stream
npm http 304 https://registry.npmjs.org/abbrev
npm http 304 https://registry.npmjs.org/sigmund
npm http 304 https://registry.npmjs.org/lru-cache
npm http 304 https://registry.npmjs.org/ansi
npm http 304 https://registry.npmjs.org/inherits
npm http 304 https://registry.npmjs.org/inherits
npm http 304 https://registry.npmjs.org/block-stream
npm http 304 https://registry.npmjs.org/inherits
node-gyp@0.8.5 node_modules/node-gyp
├── which@1.0.5
├── osenv@0.0.3
├── graceful-fs@1.2.1
├── rimraf@2.1.4
├── semver@1.1.4
├── mkdirp@0.3.5
├── request@2.9.203
├── nopt@2.1.1 (abbrev@1.0.4)
├── fstream@0.1.22 (inherits@1.0.0)
├── minimatch@0.2.12 (sigmund@1.0.0, lru-cache@2.3.0)
├── npmlog@0.0.2 (ansi@0.1.2)
├── tar@0.1.17 (inherits@1.0.0, block-stream@0.0.6)
└── glob@3.2.1 (inherits@1.0.0)


再試 node install.js



/home/hadoop/.node-gyp/0.10.7/deps/uv/include/uv.h:1411:15: error:   initializing argument 4 of ‘int uv_queue_work(uv_loop_t*, uv_work_t*, uv_work_cb, uv_after_work_cb)’ [-fpermissive]
make: *** [Debug/obj.target/gitteh/src/repository.o] Error 1
make: Leaving directory `/home/hadoop/nodejs/myapp/src/node-gitteh/build'
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/home/hadoop/nodejs/myapp/src/node-gitteh/node_modules/node-gyp/lib/build.js:256:23)
gyp ERR! stack     at ChildProcess.EventEmitter.emit (events.js:98:17)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (child_process.js:789:12)
gyp ERR! System Linux 3.5.0-17-generic
gyp ERR! command "node" "/home/hadoop/nodejs/myapp/src/node-gitteh/node_modules/.bin/node-gyp" "build"
gyp ERR! cwd /home/hadoop/nodejs/myapp/src/node-gitteh
gyp ERR! node -v v0.10.7
gyp ERR! node-gyp -v v0.8.5
gyp ERR! not ok


 


還是失敗。等等,會不會忘了 preinstall?結果沒用…。


於是我就放棄了,試試看 http://www.pygit2.org/

[python]安裝 libgit2, pygit2 on Ubuntu

作業環境:ubuntu 12.10

由於,node-gitteh 實在太難裝了。於是,我換到 pygit2 這裡。

按照 http://www.pygit2.org/install.html 一樣我也遭遇到問題。

例如,要安裝 python-dev 之類的 ( sudo apt-get install python-dev)

最後,我還是安裝成功了。

過程如下:

先下載 libgit2 的 git source,要記得,使用下列指令拿到的才行,不然之後有可能會出現錯誤(註一),據說是 libgit2 v0.18 之後的才不會有問題。

git clone git://github.com/libgit2/libgit2.git -b master

然後,使用 cmake 安裝至系統中

mkdir libgit2/build
cd libgit2/build
cmake ..
cmake --build .
sudo cmake --build . --target install

之後,下載 pygit2,並使用 setup.py 安裝

$ git clone git://github.com/libgit2/pygit2.git
$ cd pygit2
$ python setup.py install
$ python setup.py test

 


註一:錯誤訊息為:error: too many arguments to function ‘git_reference_list’


 


參考連結在此 https://github.com/libgit2/pygit2/issues/233