mac下的git的安裝與簡單的配置


git 本地操作

git 簡單介紹

1Git是分布式的SCM,SVN是集中式的

2Git每一個歷史版本號存儲完整的文件,SVN存儲文件差異

3Git可離線完畢大部分操作,SVN則相反

4Git有着更優雅的分支和合並實現

5Git有更強的撤銷改動和改動版本號歷史的能力

6Git速度更快,效率更高


一、mac 下下載 git 地址

http://git-scm.com


http://sourceforge.net/projects/git-osx-installer/



1.切換最新版本號。自己喜歡的版本號

輸入 : which  -a git

2.顯示我們用的是哪個版本號的git

git  -- version

3.確保安裝是剛剛下載的版本號

vim .bash_profile

輸入:export PATH=/usr/local/git/bin:$PATH


加載一下source .bash_profiel

再次 看一下  剛剛改動是否成功:

hairongchen:~$git —version

顯示:git version 2.2.1

二、配置git 輸入命令自己主動完畢

1.進入http://github.com/git/git

下載git 包,並解壓到一個位置


2.在終端進入剛解壓的位置

再進入 contrib/completion/ 目錄

發現有四個文件,而以下這兩個文件是我們須要的

git-completion.bash

git-prompt.sh

把上面這兩個文件復制到當前用戶home文件夾下

cp git-completion.bash ~/

cp git-prompt.sh  ~/


改動.bash_profile

vim .bash_profile


輸入下面內容

# copy contrib/copmletion/git-completion.bash to your home directory and source it

#  Linux users should add the line below to your .bashrc

. ~/git-completion.bash


#copy contrib/completion/git-prompt.sh to your home directory and source it

#Linux users should add the line below to your .bashrc

. ~/git-prompt.sh

export GIT_PS1_SHOWDIRTYSTATE=1

# export PS1='\w$(__git_ps1 " (%s)")\$'

export PS1='\u:\W$(__git_ps1 " (%s)")\$ '

上面這兩個文件主要是在git 輸入命令時能夠自己主動完畢及有內容提示

,防止輸入命令出錯


保存退出並source 一下.bash_profile



3.此時我們輸入  git confi 並按 tab鍵。就會自己主動補齊

輸入 git config - - 就會列出了一些參數


三、git 簡單配置

1>.git最主要的配置

通以上安裝及配置git 輸入命令自己主動完畢。還需最后一步就能夠使用了

git config —global user.name***

***設置成你自己的username

git config —global user.email ***

***輸入自己的email


2>git配置的三個級別

git config —system

git config —global

git config —local

local 對當前倉庫的,從優先來說,local最高,其次是global ,由於他針對是當前的用戶,最后是system


git config 文檔 三種方式

git config —help

git help config

man git-config


3>git配置的增刪改查

1.上面的添加username,email一種, 一個鍵后跟一個值


2.git config —global —add user.name rhc

add 表明他有多個這種鍵值對

能夠依據這個鍵查詢這個值 git config user.name

也能夠用git config —get user.name來查詢

通過以上兩個命令查詢,得出username是add 進去的rhc


3.git config —list —global 能夠查看所的有鍵值,發現user.name有兩個

僅僅是使用的是最后一個RHC


hairongchen:git-master$ git config --list --global

user.name=chenhairong

user.email=baitxaps@126.com

user.name=rhc


4.刪除

hairongchen:git-master$ git config --global --unset user.name

出現警告:

warning: user.name has multiple values

我們須要user.name后面加一個表達式如:git config --global --unset user.name rhc

再查:

hairongchen:git-master$ git config --list --global

user.name=chenhairong

user.email=baitxaps@126.com

發現user.name 僅僅有一個值,僅僅有一個值時 刪除就不用加表達式了如:

git config --global --unset user.name

再查:git config --get user.name,就查不到了

我們再添加回去:

git config --global user.name rhc


5.改動:

git config --global user.email bawfnhaps@163.com,把曾經的email 改了:

hairongchen:git-master$ git config --list --global

user.email=bawfnhaps@163.com

user.name=rhc



4>git子命令配置別名

checkout 取別名cogit config --global alias.co checkout

branch,status,commit配置別名例如以下:

git config --global alias.br branch

git config --global alias.st status

git config --global alias.ci commit


輸入 git c 再按tab鍵出現,多了co,ci 兩個命令。我們以后可用cicommit,cocheckout

hairongchen:git-master$ git c

c             cherry        citool        cm            commit

ca            cherry-pick   clean         co            config

checkout      ci            clone         column


git 后面接參數

輸入命令發現:git log 發現后面輸出了非常多內容

使用以下命令:git config --global alias.lol "log —oneline"

再用 git lol發現一行一行。非常整齊



免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM