安裝Git是為了在本地創(chuàng)建或管理git倉庫,同時支持其他網(wǎng)絡(luò)訪問該計算機的git倉庫。這里采用SSH協(xié)議作為Git的網(wǎng)絡(luò)通信協(xié)議,安裝Copssh后需要進行簡單的配置,這通過開始菜單下的Copssh->01. COPSSH Control Panel進行。添加用戶,選擇Shell類型為linux shell and Sftp,authentication類型選擇PassWord和Public Key,并且選中Allow TCP forwarding選項。
此時可以從本機登錄本地的ssh服務(wù):
ssh localhost
為了讓網(wǎng)絡(luò)中其它計算機通過ssh登錄,還需要修改Windows的防火墻設(shè)置,將sshd.exe添加到允許程序通過Windows防火墻通信列表中。
此時,如果我們嘗試clone服務(wù)器上的git倉庫,會遇到如下問題:
bash: git-upload-pack: command not found fatal: Could not read from remote repository.
這是因為在ssh服務(wù)找不到實現(xiàn)git傳輸協(xié)議的git-upload-pack工具,即這個工具不在PATH中,通過如下命令可以查看:
ssh user@remotemachine echo $PATH
將git-upload-pack所在的目錄添加到PATH中,可以在user主目錄下的.bashrc文件中添加:
GITPATH=`cygpath -u ‘/path/to/git-core’` EXPORT PATH=$GITPATH:$PATH
另一個需要注意的是中文編碼的配置,當Git版本1.7以后采用UTF8編碼文件名,為了同時在Windows和Linux上運行,需要注意如下配置: 1. 中文文件名
git config –sytem core.quotepath false
如果只針對特定項目設(shè)置,可以去掉–sytem,如果只針對特定用戶的全局設(shè)置,將–system改為–global。 2. 界面的編碼
git config –sytem gui.encoding utf-8
指定git-gui和gitk等界面顯示時所采用的編碼,默認為locale編碼,同時也可以被各個文件的屬性設(shè)置覆蓋。 3. 注釋的編碼
git config –system i18n.commitEncoding GB2312
提交的注釋編碼,在Windows上設(shè)置為GB2312,在Linux上設(shè)置為UTF8
git config –system i18n.logOutputEncoding GB2312
在運行g(shù)it log等命令時的將注釋轉(zhuǎn)換到的編碼,通常和commitEncoding的編碼一致。
gitconfig的選項、取值和含義可以通過man查看:
man git-config
創(chuàng)建版本庫
git init demo
用init創(chuàng)建的版本庫,默認是帶工作區(qū)的,如果創(chuàng)建一個不帶工作區(qū),用作備份的版本庫可以使用–bare選項:
git init demo.git –bare
克隆一個版本庫
git clone /path/to/demo.git
添加文件并提交
git add file git commit -m “comment”
查看當前工作區(qū)修改
git status [-s]
查看歷史提交日志
git log [–graph]
更新工作區(qū)文件
git checkout
調(diào)整提交
git reset git rebase git cherry-pick git commit
比較、重命名、刪除
git diff git mv git rm git clean [-nd] [-fd]
查看對象類型等
git ls-files git cat-file git rev-parse git rev-list
存檔和恢復(fù)
git stash save git stash list git stash pop git stash apply git stash show git stash drop git stash clear
與其他版本庫同步
git pull git push
新聞熱點
疑難解答