平台
base on Ubuntu18.04
git基础
git安装
Git 的工作需要调用 curl,zlib,openssl,expat,libiconv 等库的代码,所以需要先安装这些依赖工具。
$ apt-get install libcurl4-gnutls-dev libexpat1-dev gettext \
libz-dev libssl-dev
$ apt-get install git
$ git --version
git version 2.7.4
git用户配置
用户信息
$ git config --global user.name "baiy"
$ git config --global user.email test@baiy.com
查看配置信息
$ git config --list
user.name=baiy
user.email=****
git创建本地仓库
git init
git init newrepo
find . -name ".git" | xargs rm -Rf
git提交流程
git status .
git diff file.c
git add file
git add -u
git add .
git add -A
git commit -m "init version"
git commit -am " "
git commit --amend
git commit -a –amend
git show xxx
git查看仓库的状态
git log .
git log --oneline
git reflog
查看git提交记录内容
git show commit_id
从暂存区恢复文件
git checkout
git checkout file.c
回退git仓库到某一个提交
git reflog
git reset (--mixed) commit_id
HEAD回退commit_id这条提交的同时,保留工作目录,并清空暂存区(红)即取消add 1.c工作区 2.c暂存 3.c最后一次添加 1.c工作区 2.c工作 3.c工作 即非commit_id记录的内容全停留在工作区
git reset --soft commit_id
HEAD回退commit_id这条提交的同时,保留工作目录和暂存区中的内容,并把重置HEAD所带来的新的差异放进暂存区 1.c工作区 2.c暂存 3.c最后一次添加 1.c工作区 2.c暂存 3.c暂存 即非commit_id记录的内容将保存在暂存区
git reset --hard commit_id
将三个分区都还原到commit_id的记录(工作区和暂存区修改的内容将丢失)
撤销某一次的提交
git revert commit_id
回退commit_id这个提交到上一个版本,并重新生成提交记录
分支操作
git branch
-a
git branch dev
git branch -D dev
git checkout dev
git checkout -b dev
git merge dev
生成patch
git format-patch -1 commit_id
git format-patch commit_id
git format-patch commit_id1..commit_2
git diff [commit sha1 id] [commit sha1 id] > [diff文件名]
应用patch
git apply --check 001-Fix-debug.patch
git apply 001-Fix-debug.patch
git am 001-Fix-debug.patch
clone远程服务器
git clone <repo>
git clone <repo> <directory>
git clone gitProject@192.168.1.xxx:/Project/xxx.git
查看远程仓库地址
git remote -v
git remote add origin xxx@xxx:xxxx.git
同步远程分支
git pull
git pull origin dev
git fetch origin dev
git meger origin/dev
代码推送
git push origin dev
拓展
git仓库被锁
fatal: Unable to create 'D:/go-base/.git/index.lock': File exists.
Another git process seems to be running in this repository, e.g.
an editor opened by 'git commit'. Please make sure all processes
are terminated then try again. If it still fails, a git process
may have crashed in this repository earlier:
remove the file manually to continue.
rm .git/index.lock
git取消追踪
git rm -rf
git commit -m ""
|