转自: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 <shui6666@126.com>
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 *