git安装

一、安装git

 

[root@zabbix ~]# cat /etc/redhat-release 
CentOS Linux release 7.3.1611 (Core) 
[root@zabbix ~]# uname -r
3.10.0-514.el7.x86_64
[root@zabbix ~]# rpm -qa git
git-1.8.3.1-13.el7.x86_64
[root@zabbix ~]# yum remove git
[root@zabbix ~]# yum install gcc gcc-c++ -y

[root@zabbix ~]# yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel  perl-ExtUtils-MakeMaker -y

[root@zabbix ~]# mkdir -p /server/tools
[root@zabbix ~]# cd /server/tools/
[root@zabbix tools]# wget https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.9.0.tar.gz
[root@zabbix tools]# tar xf git-2.9.0.tar.gz 
[root@zabbix tools]# cd git-2.9.0
[root@zabbix git-2.9.0]# make prefix=/application/git
[root@zabbix git-2.9.0]# make prefix=/application/git install
[root@zabbix git]# echo 'export PATH=/application/git/bin:$PATH' >>/etc/profile
[root@zabbix git]# source /etc/profile
[root@zabbix bin]# git --version
git version 2.9.0

二、git简单操作

########环境配置
[root@zabbix test]# git config --global user.name "suffergtf"
[root@zabbix test]# git config --global user.email "suffergtf@163.com"
[root@zabbix test]# git config --global core.editor vim
[root@zabbix test]# git config --global merge.tool vimdiff
[root@zabbix test]# git config  --list
user.name=suffergtf
user.email=suffergtf@163.com
core.editor=vim
merge.tool=vimdiff
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
remote.pb.url=git://github.com/paulboone/ticgit.git
remote.pb.fetch=+refs/heads/*:refs/remotes/pb/*

#########自动补全功能,源码中contrib/completion目录下git-completion.bash文件
[root@zabbix test]# cp /server/tools/git-2.9.0/contrib/completion/git-completion.bash /etc/bash_completion.d/.git-completion.bash
[root@zabbix test]# source /etc/bash_completion.d/.git-completion.bash
[root@zabbix test]# echo "source /etc/bash_completion.d/.git-completion.bash" >>/etc/profile

[root@zabbix test]# git init      #####初始化新仓库
初始化空的 Git 仓库于
/data/test/.git/
[root@zabbix test]# ll -a
总用量 0
drwxr-xr-x. 3 root root  18 6月  26 16:53 .
drwxr-xr-x. 3 root root  18 6月  26 16:53 ..
drwxr-xr-x. 7 root root 119 6月  26 16:53 .git
[root@zabbix data]# git clone git://github.com/schacon/grit.git    #####从现有仓库克隆
正克隆到 'grit'...
remote: Counting objects: 4051, done.
remote: Total 4051 (delta 0), reused 0 (delta 0), pack-reused 4051
接收对象中: 100% (4051/4051), 2.04 MiB | 405.00 KiB/s, 完成.
处理 delta 中: 100% (1465/1465), 完成.
检查连接... 完成。
[root@zabbix data]# ll
总用量 0
drwxr-xr-x. 6 root root 256 6月  26 17:04 grit
drwxr-xr-x. 3 root root  18 6月  26 16:53 test
[root@zabbix data]# git clone git://github.com/schacon/grit.git mygrit      ####从现有仓库克隆,并重命名
正克隆到 'mygrit'...
remote: Counting objects: 4051, done.
remote: Total 4051 (delta 0), reused 0 (delta 0), pack-reused 4051
接收对象中: 100% (4051/4051), 2.04 MiB | 366.00 KiB/s, 完成.
处理 delta 中: 100% (1465/1465), 完成.
检查连接... 完成。
[root@zabbix grit]# git status      #########查看仓库状态
On branch master  
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean      ####表示没有工作目录很干净,没有未提交的变更
[root@zabbix grit]# touch readme
[root@zabbix grit]# git status
On branch master
Your branch is up-to-date with 'origin/master'.
Untracked files:                      ######有未跟踪文件
  (use "git add <file>..." to include in what will be committed)

    readme                          ######未跟踪文件名

nothing added to commit but untracked files present (use "git add" to track)   
[root@zabbix grit]# git add readme      #####跟踪新建的文件,并将文件暂存
[root@zabbix grit]# git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes to be committed:                #####有变更需要提交
  (use "git reset HEAD <file>..." to unstage)

    new file:   readme              #####需要提交的文件名

[root@zabbix grit]# echo "#######" >>benchmarks.rb
[root@zabbix grit]# git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

    new file:   readme

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

    modified:   benchmarks.rb

[root@zabbix grit]# git add benchmarks.rb     ####将已追踪的文件暂存
[root@zabbix grit]# git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

    modified:   benchmarks.rb
    new file:   readme

[root@zabbix grit]# echo "*.log" >>.gitignore     #####将部分文件忽略暂存
[root@zabbix grit]# cat .gitignore
pkg
.DS_Store
*.log
#####忽略暂存,匹配后面跟\的表示目录,前面加!表示取反######

[root@zabbix grit]# git diff      ######查看已修改文件与已暂存文件的更新部分
diff --git a/.gitignore b/.gitignore
index c06a73d..04d3c2f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,3 @@
 pkg
 .DS_Store
+*.log
[root@zabbix grit]# git diff --staged      #####查看已暂存文件和已提交文件的更新部分
diff --git a/benchmarks.rb b/benchmarks.rb
index e445e28..6a2c084 100644
--- a/benchmarks.rb
+++ b/benchmarks.rb
@@ -127,3 +127,4 @@ end
 main()
 
 ##pp Grit::GitRuby.cache_client.stats
+#######
diff --git a/readme b/readme
new file mode 100644
index 0000000..e69de29

[root@zabbix grit]# git commit -m "this is a test"      #####将暂存区域文件提交,-m 提交说明
[master 10b86a8] this is a test
 Committer: ge tf <root@zabbix.suffergtf.com>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:

    git config --global user.name "Your Name"
    git config --global user.email you@example.com

After doing this, you may fix the identity used for this commit with:

    git commit --amend --reset-author

 3 files changed, 2 insertions(+)
 create mode 100644 readme


[root@zabbix grit]# git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

    modified:   readme

no changes added to commit (use "git add" and/or "git commit -a")
[root@zabbix grit]# git commit -a -m "111"      ####跳过暂存,直接提交
[master 9ec8d11] 111
 Committer: ge tf <root@zabbix.suffergtf.com>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:

    git config --global user.name "Your Name"
    git config --global user.email you@example.com

After doing this, you may fix the identity used for this commit with:

    git commit --amend --reset-author

 1 file changed, 1 insertion(+)

[root@zabbix grit]# git rm -f  111    #####将暂存文件,已提交文件从已追踪文件删除,并且删除文件本身
rm '111'
[root@zabbix grit]# git rm --cache 111    #####仅将暂存文件,已提交文件从已追踪文件删除,不删除文件本身
rm '111'

[root@zabbix grit]# git log        ###########查看提交历史
commit 10b9cd63096eba6074dba1c1331fa162c557e689      ####哈希值
Author: ge tf <root@zabbix.suffergtf.com>        ####作者
Date:   Tue Jun 26 22:11:57 2018 +0800          ####提交时间

    222                           #####提交说明

commit 91aca7508544c764c6bff91c5e96eff0052fd2d4
Author: ge tf <root@zabbix.suffergtf.com>
Date:   Tue Jun 26 22:08:34 2018 +0800

    11

[root@zabbix grit]# git commit --amend    ####文件没有修改的情况下,修改提交说明;有文件修改的情况下,可以重新提交,将之前提交的和漏提交的作为同一次提交

[root@zabbix grit]# git status
On branch master
Your branch is ahead of 'origin/master' by 5 commits.
  (use "git push" to publish your local commits)
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

    modified:   111

[root@zabbix grit]# git reset HEAD 111        #######取消已暂存的文件
Unstaged changes after reset:
M    111
[root@zabbix grit]# git status
On branch master
Your branch is ahead of 'origin/master' by 5 commits.
  (use "git push" to publish your local commits)
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

    modified:   111

no changes added to commit (use "git add" and/or "git commit -a")

[root@zabbix grit]# git diff       #####查看修改内容
diff --git a/111 b/111
index ad3a1a1..cb1316c 100644
--- a/111
+++ b/111
@@ -1,2 +1,3 @@
 222
 2222
+test
[root@zabbix grit]# git checkout -- 111      ####撤销修改
[root@zabbix grit]# tail 111            
222
2222

 

转载于:https://www.cnblogs.com/suffergtf/p/9168383.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值