Preface
Git (pronounced /gɪt/) is an open source distributed version control system that can effectively and quickly handle the version management of projects from very small to very large.
Git is an open source version control software developed by Linus Torvalds to help manage the development of the Linux kernel
Official website https://git-scm.com/
installation steps
1. Install dependent libraries
yum -y install libcurl-devel expat-devel curl-devel gettext-devel openssl-devel zlib-devel
yum -y install gcc perl-ExtUtils-MakeMaker
2. Download the source code
cd /usr/local/src/
wget https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.9.5.tar.gz
3. Unzip
tar -zvxf git-2.9.5.tar.gz
4. Compile
cd git-2.9.5
make prefix=/usr/local/src/git-2.9.5 all
make prefix=/usr/local/src/git-2.9.5 install
5. Set environment variables
vi /etc/profile
Press i in English input state to enter insert mode, add the following configuration
export PATH=/usr/local/src/git-2.9.5/bin:$PATH
Press esc to enter : wq to save and exit, compile /etc/profile to make the configuration effective
source /etc/profile
6. View the version number
git --version
If a version number appears, it means success!
7. Configuration
cd /root/.ssh
git config --global user.name "root"
git config --global user.email "[email protected]"
git config --global core.autocrlf false
git config --global gui.encoding utf-8
8. Generate ssh-key
ssh-keygen -t rsa -C "[email protected]"
9. View the secret key
cat ~/.ssh/id_rsa.pub
Common commands
Manual https://git-scm.com/book/zh/v2
http://gitref.justjavac.com/branching/#branch
1. View
git branch 查看本地所有分支
git branch -a 查看所有的分支
git branch -r 查看远程所有分支
git status 查看当前状态
git config --list 看所有用户
git ls-files 看已经被提交的
git log 看你commit的日志
git diff 查看尚未暂存的更新
git diff --cached 查看尚未提交的更新
git remote show origin 显示远程库origin里的资源
2. Submit/Pull/Push
git add -A 提交所有变化
git add -u 提交被修改(modified)和被删除(deleted)文件,不包括新文件(new)
git add . 提交新文件(new)和被修改(modified)文件,不包括被删除(deleted)文件
git add [file name] 添加一个文件到git index
git commit 提交
git commit -am "init" 提交并且加注释
git commit -a 提交当前repos的所有的改变
git commit -v 当你用-v参数的时候可以看commit的差异
git commit -m "commit a" 添加commit信息
git commit -a -v 一般提交命令
git commit -a -m "log_message" (-a是提交所有改动,-m是加入log信息) 本地修改同步至服务器端 :
git remote add origin url 添加远程版本库
git push origin master 将文件给推到服务器上
git push origin master:develop
git push origin master:hb-dev 将本地库与服务器上的库进行关联
git push (远程仓库名) (分支名) 将本地分支推送到服务器上去。
git pull 本地与服务器端同步
git fetch 相当于是从远程获取最新版本到本地,不会自动merge
3. Branch switching/creating/merging
git checkout --track origin/dev 切换到远程dev分支
git checkout -b dev 建立一个新的本地分支dev
git checkout dev 切换到本地dev分支
git branch branch_0.1 master 从主分支master创建branch_0.1分支
git branch -m branch_0.1 branch_1.0 将branch_0.1重命名为branch_1.0
git merge origin/dev 将分支dev与当前分支进行合并
4. Code copy/temporary storage
git clone git://github.com/schacon/grit.git 从服务器上将代码给拉下来
git stash push 将文件给push到一个临时空间中
git stash pop 将文件从临时空间pop下来