git常用命令整理

(gnome-ssh-askpass:5864): Gtk-WARNING **: cannot open display:
unset SSH_ASKPASS

复制一个已创建的仓库:
git clone ssh://useruseruser@domain.com/repo.git
git clone http://172.20.10.60:3000/xxxxxx/xxxxxx_war.git

git config —global http.postBuffer 524288000
git config —global user.email “iteemo@xxxxxx.com”
git config —global user.name “iteemo”

从命令行创建一个新的仓库
touch README.md
git init
git add README.md
git commit -m “first commit”
git remote add origin http://172.20.10.60:3000/xxxxxx/xxxxxx_war.git
git push -u origin master
git push origin +master 强制推送

从命令行推送已经创建的仓库
git remote add origin http://172.20.10.60:3000/xxxxxx/xxxxxx_war.git
git push -u origin master

本地修改
git checkout — . 撤销本地git未提交操作
git status #显示工作路径下已修改的文件
git diff #显示与上次提交版本文件的不同
git add #把当前所有修改添加到下次提交中
git commit -a #提交本地的所有修改
git commit -m ‘message here’ #附加消息提交
git commit —date=”date --date='n day ago'“ -am “Commit Message” #提交,并将提交时间设置为之前的某个日期

提交历史
git log #从最新提交开始,显示所有的提交记录(显示hash, 作者信息,提交的标题和时间)
git log —author=”username” #显示某个用户的所有提交

分支与标签
git branch #列出本地的所有分支
git checkout #切换分支
git checkout -b #创建新的本地分支
git branch #基于当前的本地分支创建新的分支
git branch —track #基于远程分支创建新的可追溯的分支
git branch -d #删除本地分支

git tag #给当前版本打标签
创建附注标签
git tag -a v0.1.2 -m “0.1.2版本”
列出标签
git tag 查看所有标签
git checkout [tagname] 切换到标签
git tag -d v0.1.2 # 删除标签
查看远程版本:$ git tag -r
合并远程仓库的tag到本地:$ git pull origin —tags
上传本地tag到远程仓库:$ git push origin —tags
创建带注释的tag:$ git tag -a [name] -m ‘yourMessage’
git push origin v0.1.2 #将v0.1.2标签提交到git服务器
git push origin —tags #将本地所有标签一次性提交到git服务器
查看远程tag
git pull
git tag

git fetch origin tag v0.1.2 #获取远程单个tag
git push origin :refs/tags/v0.1.2 删除远程的tag

更新与发布
git remote -v #列出当前配置的远程端
git fetch #下载远程端版本,但不合并到HEAD中
git pull origin master #将远程端版本合并到本地版本中

git push origin [name] #创建远程版本(本地版本push到远程)
提交分支数据到远程服务器:
git push -u origin master
git push origin develop
删除远程版本:$ git push origin :refs/tags/[name]
git push origin :develop #删除远程develop分支

合并
git merge aaa 合并aaa分支到当前分支
git checkout master
&& git merge —no-ff release-1.2-20150519(合并到master分支)
git tag -a online-1.2-20150519(打TAG记录里程碑)
git checkout
develop && git merge —no-ff release-1.2-20150519(合并到develop分支)

版本回退
用git log命令查看提交记录或者git log —pretty=oneline 简洁显示
git log —pretty=oneline
bb3b8059ea7d6decca6edb99a9a281c08c5cc496 add aaa
5d71719545dd1c7da82a3d86492dd353e8a2c990 add abc.html

此处建议直接commitid
git reset —hard 5d7171954
一下两条不建议使用
git reset —hard HEAD^ 会退到上第一个版本
git reset —hard HEAD^^ 回退到上两个版本
git reset —hard bb3b8059ea 回到最后的版本
另外
git reset commitid(或 head guid)

git reset —hard commitid(或 head guid)
是不一样的,这得按需使用。
一般,完全回滚操作使用第二个,仅回滚近期提交使用第一个

合并冲突
http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/001375840202368c74be33fbd884e71b570f2cc3c0d1dcf000
廖雪峰的那个
主要是

配置git
git config —global user.name “Your Name”
git config —global user.email “email@example.com”

安装git2.43 支持git命令自动补全

!/bin/bash

#

Check if user is root

if [ $(id -u) != “0” ]; then

echo "Error: You must be root to run this script, please use root to install"

exit 1

fi

cur_dir=$(pwd)

function checkgit() {

if [ -e git-2.4.3.tar.gz ]; then

    echo "git-2.4.3.tar.gz [found]"

else

    wget -c https://www.kernel.org/pub/software/scm/git/git-2.4.3.tar.gz

fi

}

function instgit() {

checkgit &&

yum -y remove git &&

yum -y install curl-devel expat-devel gettext-devel openssl-devel zlib-devel asciidoc gcc perl-ExtUtils-MakeMaker

cd $cur_dir &&

tar zxmf git-2.4.3.tar.gz &&

cd git-2.4.3 &&

./configure prefix=/usr/local/git &&

make && make install &&

ln -sv /usr/local/git/bin/* /usr/bin/

echo git --version
echo pwd
find $cur_dir -name “git-completion.bash” -exec cp {} /etc/bash_completion.d/ ;
. /etc/bash_completion.d/git-completion.bash

}

instgit 2>&1 | tee /root/mysql-install.log

原文地址:https://www.cnblogs.com/iteemo/p/4967738.html