GIT 使用

轉自:http://blog.csdn.net/shui1025701856/article/details/7438342

1. git 的安裝
apt-get install git git-core
2. 項目倉庫的建立(git init)
mkdir git //建立倉庫目錄
cd git //進入倉庫目錄
git init //在當前目錄下建一個倉庫
/git# git init
Initialized empty Git repository in /wolf/git/.git/
前面的三個命令建立了一個本地的git倉庫,這個倉庫現在是
一個空倉庫
git# git status//查看當前倉庫的狀態
# On branch master
#
# Initial commit
#
nothing to commit (create/copy files and use "git add" to track)
$git log #查看當前倉庫的歷史日誌
fatal: bad default revision 'HEAD'
(由於倉庫裏沒有任提交在裏面,所以它會報這個錯)
3. 在倉庫裏添加內容git add和git commit
git# echo "hello git" > readme.txt
git# git add readme.txt//將readme.txt添加到暫存區中
git commit -m "git init"//將修改提交到本地倉庫中
git# git commit -m "git init"
# On branch master
nothing to commit (working directory clean)
現在這個工作目錄裏沒有什麼要提交的東西,它是整潔的
/git# git log可以看到剛纔的提交記錄


/*這一串字符就是我們這次創建的提交的名字
Git通過對提交內容進行SHA1 Hash運算,得到它們的SHA1串值,
作爲每個提交的唯一標識。根據一般的密碼學原理來說,
如果兩個提交的內容不相同,那麼它們的名字就不會相同;
反之,如果它們的名字相同,就意味着它們的內容也相同*/


commit ce7932ee5ae25303772ee72551ade8a2fed452e2
Author: root <root@bshui.(none)>
Date: Sat Apr 7 16:40:52 2012 +0800


git init
4. git diff #查看倉庫裏未暫存內容和倉庫已提交內容的差異
git# git diff
diff --git a/readme.txt b/readme.txt
index b846b66..f2aa86d 100644
--- a/readme.txt
+++ b/readme.txt
@@ -1 +1 @@
-change it
+hello
可以生成補丁
5. git status 顯示當前的狀態
/wolf/git# git status
# On branch master
# Changed but not updated:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: readme.txt
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# a.patch
no changes added to commit (use "git add" and/or "git commit -a")
6. git log 查看版本歷史
git log
commit a90b64fbd5a900185a6f75a79359014455cdc919
Author: Daemon <[email protected]>
Date: Sat Apr 7 16:50:16 2012 +0800


change it


commit ce7932ee5ae25303772ee72551ade8a2fed452e2
Author: root <root@bshui.(none)>
Date: Sat Apr 7 16:40:52 2012 +0800
7. git show查看版本號對應版本的歷史
8. 用git協同工作
本地,在本地新建一個目錄test
cd test
/wolf/test# git clone /wolf/git/
Initialized empty Git repository in /wolf/test/git/.git/




9. git apply相當於patch命令。
--check 檢查能否正常打上補丁,-v verbose模式, -R reverse模式,反打補丁。

10. git 通過ssh 進行認證連接

使用ssh-keygen -t rsa生成本地密匙和公匙
Your identification has been saved in /home/shuixb/.ssh/id_rsa.
Your public key has been saved in /home/shuixb/.ssh/id_rsa.pub.
vi /homegit/.ssh/authorized_keys
把id_rsa.pub的公匙複製到服務器的/home/git/.ssh/authorized_keys 中

mkdir samsung.ok.git
git init
git add samsung
git commit -m "add samsung"
git clone /home/share/git/samsung.ok.git/

11.新建git用戶作爲服務器,把id_rsa.pub的公匙複製到服務器的/home/git/.ssh/authorized_keys 中
sudo useradd git
sudo passwd git

git push 問題
remote: error: refusing to update checked out branch: refs/heads/master
remote: error: By default, updating the current branch in a non-bare repository
這是由於git默認拒絕了push操作,需要進行設置,修改.git/config添加如下代碼:

[receive]
denyCurrentBranch = ignore

其它用戶git權限不夠
error: insufficient permission for adding an object to repository database ./objects
cd ./git
chmod 777 -R *

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章