1. 程式人生 > >Git安裝及配置

Git安裝及配置

官方文件

https://git-scm.com/book/zh/v2

 

 

git 10.0.0.200

jenkins 10.0.0.201

 

Git準備環境
 getenforce
yum install git
 
[[email protected] ~]# git version
git version 1.8.3.1
[[email protected] ~]# git config
用法:git config [選項]
 
配置檔案位置
    --global              使用全域性配置檔案
    --system              使用系統級配置檔案
    --local               使用版本庫級配置檔案
    -f, --file <檔案>     使用指定的配置檔案
    --blob <blob-id>      read config from given blob object
 
操作
    --get                 獲取值:name [value-regex]
    --get-all             獲得所有的值:key [value-regex]
    --get-regexp          根據正則表示式獲得值:name-regex [value-regex]
    --replace-all         替換所有匹配的變數:name value [value_regex]
    --add                 新增一個新的變數:name value
    --unset               刪除一個變數:name [value-regex]
    --unset-all           刪除所有匹配項:name [value-regex]
    --rename-section      重新命名小節:old-name new-name
    --remove-section      刪除一個小節:name
    -l, --list            列出所有
    -e, --edit            開啟一個編輯器
    --get-color <slot>    找到配置的顏色:[預設]
    --get-colorbool <slot>
                          找到顏色設定:[stdout-is-tty]
 
型別
    --bool                值是 "true" 或 "false"
    --int                 值是十進位制數
    --bool-or-int         值是 --bool or --int
    --path                值是一個路徑(檔案或目錄名)
 
其它
    -z, --null            終止值是NUL位元組
    --includes            查詢時參照 include 指令遞迴查詢
 

 

配置

 

[ro[email protected] ~]# git config --global user.name "ckh"
[[email protected] ~]# git config --global user.email [email protected]
[[email protected] ~]# git config --global color.ui true
[[email protected] ~]# git config --list
user.name=ckh
user.[email protected]
color.ui=true
[[email protected] ~]# cat .gitconfig
[user]
 name = ckh
 email = [email protected]
[color]
 ui = true
 

 

GIT常規使用

git四種狀態

 

 branches # 分支目錄

 config   # 定義專案特有的配置選項

 description  # 僅供git web程式使用

 HEAD # 指示當前的分支

 hooks # 包含git鉤子檔案

 info # 包含一個全域性排除檔案(exclude檔案)

 objects # 存放所有資料內容,有info和pack兩個子資料夾

 refs # 存放指向資料(分支)的提交物件的指標

 index # 儲存暫存區資訊,在執行git init的時候,這個檔案還沒有 

 

初始化目錄

[[email protected] ~]# mkdir git_data
[[email protected] ~]# cd git_data/
[[email protected] git_data]# git init
初始化空的 Git 版本庫於 /root/git_data/.git/
 
[[email protected] git_data]# git status
# 位於分支 master
#
# 初始提交
#
無檔案要提交(建立/拷貝檔案並使用 "git add" 建立跟蹤)
 
[[email protected] git_data]# touch a b c
[[email protected] git_data]# git status
# 位於分支 master
#
# 初始提交
#
# 未跟蹤的檔案:
#   (使用 "git add <file>..." 以包含要提交的內容)
#
# a
# b
# c
提交為空,但是存在尚未跟蹤的檔案(使用 "git add" 建立跟蹤)
[[email protected] git_data]# git add a
[[email protected] git_data]# git status
# 位於分支 master
#
# 初始提交
#
# 要提交的變更:
#   (使用 "git rm --cached <file>..." 撤出暫存區)
#
# 新檔案:    a
#
# 未跟蹤的檔案:
#   (使用 "git add <file>..." 以包含要提交的內容)
#
# b
# c
[[email protected] git_data]# git rm -f a
rm 'a'
[[email protected] git_data]# git status
# 位於分支 master
#
# 初始提交
#
# 未跟蹤的檔案:
#   (使用 "git add <file>..." 以包含要提交的內容)
#
# b
# c
提交為空,但是存在尚未跟蹤的檔案(使用 "git add" 建立跟蹤)
[[email protected] git_data]# ls
b  c
[[email protected] git_data]# git add b
[[email protected] git_data]# git commit -m "add file b"
[master(根提交) 0d0feec] add file b
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 b
[[email protected] git_data]# git status
# 位於分支 master
# 未跟蹤的檔案:
#   (使用 "git add <file>..." 以包含要提交的內容)
#
# c
提交為空,但是存在尚未跟蹤的檔案(使用 "git add" 建立跟蹤)
 
#每次提交的日誌資訊
[[email protected] git_data]# git log
commit caa84b88f31b5acdcf627b3359ca0719a5db2846
Author: ckh <[email protected]>
Date:   Thu Nov 15 10:41:05 2018 +0800
 
    add file a c
 
commit 0d0feec1d0849c4496ed78631c223fd30876178e
Author: ckh <[email protected]>
Date:   Thu Nov 15 10:25:28 2018 +0800
 
    add file b
 

 

 

MV改名 git認為是刪除了檔案 然後回滾

[[email protected] git_data]# touch test
[[email protected] git_data]# git add test
[[email protected] git_data]# git status
# 位於分支 master
# 要提交的變更:
#   (使用 "git reset HEAD <file>..." 撤出暫存區)
#
# 新檔案:    test
#
[[email protected] git_data]# mv test test.txt
[[email protected] git_data]# git status
# 位於分支 master
# 要提交的變更:
#   (使用 "git reset HEAD <file>..." 撤出暫存區)
#
# 新檔案:    test
#
# 尚未暫存以備提交的變更:
#   (使用 "git add/rm <file>..." 更新要提交的內容)
#   (使用 "git checkout -- <file>..." 丟棄工作區的改動)
#
# 刪除:      test
#
# 未跟蹤的檔案:
#   (使用 "git add <file>..." 以包含要提交的內容)
#
# test.txt
[[email protected] git_data]# git add test.txt
[[email protected] git_data]# git status
# 位於分支 master
# 要提交的變更:
#   (使用 "git reset HEAD <file>..." 撤出暫存區)
#
# 新檔案:    test
# 新檔案:    test.txt
#
# 尚未暫存以備提交的變更:
#   (使用 "git add/rm <file>..." 更新要提交的內容)
#   (使用 "git checkout -- <file>..." 丟棄工作區的改動)
#
# 刪除:      test
#
[[email protected] git_data]# git checkout  test
[[email protected] git_data]# ll
總用量 0
-rw-r--r-- 1 root root 0 11月 15 10:38 a
-rw-r--r-- 1 root root 0 11月 15 10:21 b
-rw-r--r-- 1 root root 0 11月 15 10:21 c
-rw-r--r-- 1 root root 0 11月 15 10:52 test
-rw-r--r-- 1 root root 0 11月 15 10:50 test.txt
 

 

撤回暫存區

[[email protected] git_data]# git reset HEAD test test.txt
[[email protected] git_data]# git status
# 位於分支 master
# 未跟蹤的檔案:
#   (使用 "git add <file>..." 以包含要提交的內容)
#
# test
# test.txt
提交為空,但是存在尚未跟蹤的檔案(使用 "git add" 建立跟蹤)
 

 

git mv 工作區和暫存區同時改

[root@hostname200 git_data]# ls
a  b  c  test  test.txt
[root@hostname200 git_data]# rm test.txt
rm:是否刪除普通空檔案 "test.txt"?y
[root@hostname200 git_data]# git add test
[root@hostname200 git_data]# git status
# 位於分支 master
# 要提交的變更:
#   (使用 "git reset HEAD <file>..." 撤出暫存區)
#
# 新檔案:    test
#
[root@hostname200 git_data]# git mv test test.txt
[root@hostname200 git_data]# git status
# 位於分支 master
# 要提交的變更:
#   (使用 "git reset HEAD <file>..." 撤出暫存區)
#
# 新檔案:    test.txt
#
 

 

 

[root@hostname200 git_data]# echo aaa> test.txt
[root@hostname200 git_data]# ll
總用量 4
-rw-r--r-- 1 root root 0 11月 15 10:38 a
-rw-r--r-- 1 root root 0 11月 15 10:21 b
-rw-r--r-- 1 root root 0 11月 15 10:21 c
-rw-r--r-- 1 root root 4 11月 15 10:57 test.txt
[root@hostname200 git_data]# cat test.txt
aaa
[root@hostname200 git_data]# git status
# 位於分支 master
# 要提交的變更:
#   (使用 "git reset HEAD <file>..." 撤出暫存區)
#
# 新檔案:    test.txt
#
# 尚未暫存以備提交的變更:
#   (使用 "git add <file>..." 更新要提交的內容)
#   (使用 "git checkout -- <file>..." 丟棄工作區的改動)
#
# 修改:      test.txt
#
 
#比對 工作目錄 和暫存區的檔案不同
[root@hostname200 git_data]# git diff test.txt
diff --git a/test.txt b/test.txt
index e69de29..72943a1 100644
--- a/test.txt
+++ b/test.txt
@@ -0,0 +1 @@
+aaa
 
# 提交暫存區
[root@hostname200 git_data]# git add test.txt
[root@hostname200 git_data]# git diff test.txt  # 沒有修改狀態資訊
[root@hostname200 git_data]# git status   #新檔案
# 位於分支 master
# 要提交的變更:
#   (使用 "git reset HEAD <file>..." 撤出暫存區)
#
# 新檔案:    test.txt
 
#提交倉庫
[root@hostname200 git_data]# git commit -m "add test.txt file aaa"
[master 4c5ce8b] add test.txt file aaa
 1 file changed, 1 insertion(+)
 create mode 100644 test.txt
[root@hostname200 git_data]# git status
# 位於分支 master
無檔案要提交,乾淨的工作區
# 倉庫和暫存區 的區別
[root@hostname200 git_data]# git diff --cached test.txt
 
# 修改 在提交在比較
[root@hostname200 git_data]# echo bbb>>test.txt
[root@hostname200 git_data]# git add test.txt
[root@hostname200 git_data]# git diff --cached test.txt
diff --git a/test.txt b/test.txt
index 72943a1..dbee026 100644
--- a/test.txt
+++ b/test.txt
@@ -1 +1,2 @@
 aaa
+bbb
 
#這是 工作目錄 和暫存區對比
[root@hostname200 git_data]# git diff test.txt
[root@hostname200 git_data]# git diff  #所有對比
 

 

已經在倉庫的檔案 修改後快速提交 -am

[[email protected] git_data]# echo ccc>>test.txt
[[email protected] git_data]# cat test.txt
aaa
bbb
ccc
[[email protected] git_data]# git commit -am "add test file ccc"
[master 93bb2f6] add test file ccc
 1 file changed, 2 insertions(+)
[[email protected] git_data]# git status   #顯示工作區狀態
# 位於分支 master
無檔案要提交,乾淨的工作區
 
 

 

git基礎命令
git add file或git add . 將工作目錄檔案新增到暫存區
git rm --cached 只刪暫存區
git rm -f file 刪除暫存區和工作目錄原始檔,不會刪除倉庫裡面的檔案。
git status
git commit -m "修改了很多bug"
git checkout -- file 放棄工作區的改動,修改的部份會被回滾
git mv 這種改名操作會被跟蹤
git diff file 比對的工作目錄和暫存區域
git diff --cached file 比對暫存區和倉庫裡的區別,前提是在工作區修改後要先將檔案新增到暫存區才能比對git add file
git commit -am "日誌" 適用於已要提交到倉庫的檔案,如果在工作目錄修改了,可以直接這樣提交到倉庫,不需要再新增一次再提交。
git log檢視日誌
git log --oneline以單行顯示日誌

 

# 提交日誌記錄   oneline 一行簡單顯示資訊
[[email protected] git_data]# git log --oneline
93bb2f6 add test file ccc
4c5ce8b add test.txt file aaa
caa84b8 add file a c
0d0feec add file b
 
# 多了 HEAD指向 最新一次提交資訊   當前指標指向哪裡
[[email protected] git_data]# git log --oneline --decorate
93bb2f6 (HEAD, master) add test file ccc
4c5ce8b add test.txt file aaa
caa84b8 add file a c
0d0feec add file b
 
#顯示每次版本修改的詳細資訊
[[email protected] git_data]# git log -p
commit 93bb2f6caf31e6f78c80fcc9281a521f69447634
Author: ckh <[email protected]>
Date:   Thu Nov 15 11:06:48 2018 +0800
 
    add test file ccc
 
diff --git a/test.txt b/test.txt
index 72943a1..1802a74 100644
--- a/test.txt
+++ b/test.txt
@@ -1 +1,3 @@
 aaa
+bbb
+ccc
 
# -2 顯示2條版本提交資訊
[[email protected] git_data]# git log -2
commit 93bb2f6caf31e6f78c80fcc9281a521f69447634
Author: ckh <[email protected]>
Date:   Thu Nov 15 11:06:48 2018 +0800
 
    add test file ccc
 
commit 4c5ce8b5200c48c6157e3a3f66cbc7780253e770
Author: ckh <[email protected]>
Date:   Thu Nov 15 11:00:19 2018 +0800
 
    add test.txt file aaa
 

 

 

#倉庫 如何恢復 之前的版本

[[email protected] git_data]# echo dddd >test.txt
[[email protected] git_data]# ls
a  b  c  test.txt
[[email protected] git_data]# cat test.txt
dddd
[[email protected] git_data]# git commit -am "add dddd"
[master f634e8b] add dddd
 1 file changed, 1 insertion(+), 3 deletions(-)
[
            
           

相關推薦

Git安裝配置

官方文件 https://git-scm.com/book/zh/v2     git 10.0.0.200 jenkins 10.0.0.201   Git準備環境 getenforce yum install git [[email 

Linux下Git安裝配置較詳細

1.下載git原始碼 目前最新版本下載地址:https://mirrors.edge.kernel.org/pub/software/scm/git/ --下載 :wget https://mirrors.edge.kernel.org/pub/software/scm/git/g

Git 安裝配置

首先下載GIT進行安裝,最好不要安裝在系統盤C盤裡,以免產生不必要的錯誤。 配置過程: 1.生成public key. 在git bash中執行C:\Program Files (x86)\Get\usr\bin\ssh-keygen.exe -t rsa 如下:

Linux下Git安裝配置

yum安裝版本可能較低 如果採用yum安裝git的方式:  yum install git  如果採用yum安裝了git需要先解除安裝:  yum remove git 原始碼安裝 安裝依賴的包  yum install curl-devel expat-deve

IntelliJ IDEA +git安裝配置

一.IntelliJ IDEA安裝 從官網下載安裝包,按網上教程安裝即可,基本都是預設。。。。 二.git安裝 從網上下載安裝包,按照教程安裝即可。。。。。。 IntelliJ IDE

[Git] Git安裝配置

class span odi commit ret 打印 cat apt-get gre 1. Ubuntu 下安裝 git sudo apt-get install git 2. 配置郵箱和用戶名 git config --global user.name mz

centos下git安裝配置

⑴.檢視系統是否已經安裝 git :git --version ⑵.yum 安裝git:yum install git ⑶.安裝成功:yum --version ⑷.解除安裝git:yum remove git

Windows下Git 安裝配置使用

1、安裝 2、配置 建立SSH 一、引子: 什麼是ssh:ssh是Secure Shell(安全外殼協議)的縮寫,建立在應用層和傳輸層基礎上的安全協議。為了便於訪問github,要生成ssh公鑰,這樣就不用每一次訪問github都要輸入使用者名稱和密碼。 二、生

Git安裝配置、上傳公鑰、測試登入clone庫(使用者教程)

1安裝Git 以windows為例,Linux和Mac OS X的同學請百度。 由於雙擊Git-1.9.4-preview20140815.exe,安裝過程很簡單,這裡不再贅述。 但是有幾點注意的地方: (1) 選擇目標安裝位置時,最好不使用預設的路徑如”C:\Progra

ubuntu下安裝配置git的方法(github)

轉自:http://blog.csdn.net/tina_ttl安裝Git一個全新的ubunt系統,需要安裝Git(系統是不具有該工具的),方法如下: 在terminel中輸入如下命令:sudo apt-get install git git-core git-gui git-doc git-svn git-

centos7安裝配置git

yum –y install git 出現Complete!說明安裝成功 使用git --version檢視git版本 git --version git version 1.8.3.1 配置git 在資料夾下使用git init初始化git 然後就可以使用git

git 安裝基本配置

git 基本上來說是開發者必備工具了,在伺服器裡沒有 git 實在不太能說得過去。何況,沒有 git 的話,面向github程式設計 從何說起,如同一個程式設計師斷了左膀右臂。 你對流程熟悉後,只需要一分鐘便可以操作完成 原文地址: 伺服器 ssh key 以及 git 的配置 系列文章: 伺服器運維

GIT安裝詳細使用

gitLinux安裝Git及詳細使用Git是目前世界上最先進的分布式版本控制系統。Git的與SVN最主要的區別 ,Git是分布式版本控制系統,那麽它就沒有中央服務器的,每個人的電腦就是一個完整的版本庫,只需把各 自的修改推送給對方;SVN是集中式版本控制系統,版本庫是集中放在中央服務器的,集中式版本控制系統是

kali linux安裝配置

bsp -i upgrade 文件 unit 設置 ade 一個 linux用戶 kali linux用戶名:root 密碼:之前設置過的密碼 ---------------------------------------------------------------

Ubuntu系統下OpenLDAP的安裝配置

操作系統 ldap 前言LDAP(Lightweight Directory Access Protocol)是基於X.500標準的輕量級目錄訪問協議,在Unix操作系統裏面,和NIS,DNS一樣,屬於名稱服務(Naming Service)。本文描述了如何在Ubuntu操作系統上面,搭建LDAP服務

linux應用之xampp集成環境的安裝配置(centos)

其他 配置文件 ln -s 提示 config 執行權 listen location x64 1.xampp集成環境的下載   在xampp的官網上選擇對應系統的版本進行下載,官網地址:https://www.apachefriends.org/zh_cn/index.h

Solr - 無*.war版solr安裝配置

新建 9.png quick none sources res .com eight spl 1.將 solr 壓縮包中*\server\solr-webapp\文件夾下有個webapp文件夾,將之復制到Tomcat\webapps\目錄下,並改成solr (名字隨意,通過

zabbix(1)--服務器端安裝配置

zabbix-server1、zabbix-server配置zabbix版本選擇LTS的3.0版本、server端OS版本為RHEL 6.5配置zabbix倉庫,進行yum安裝zabbix~]# cd /etc/yum.repos.d/ yum.repos.d]# vim zabbix.repo [zab

Tomcat安裝配置教程

exe hot str 打開 內容 cbe bfc pre f11 用來進行web開發的工具有很多,Tomcat是其中一個開源的且免費的java Web服務器,是Apache軟件基金會的項目。電腦上安裝配置Tomcat的方法和java有些相同,不過首先需要配置好ja

Java基礎軟件的安裝配置Javascript的運行

bsp 系統 script static ati pat ogr javascrip 安裝路徑 1.Jdk的安裝及環境變量配置: (1)計算機-屬性-高級系統設置。 (2)環境變量-系統變量-輸入變量名JAVA_HOME-輸入變量值C:\Pr