初始化配置
git config --global user.name "Your Name Comes Here"
git config --global user.email you@yourdomain.example.com
git config --global credential.helper cache
git config --global credential.helper 'cache --timeout=3600'
git config --list
增删改查
git help
git add <file>
git add .
git rm <file>
git rm <file>
git reset <file>
git reset
git reset
git revert <$id>
git revert HEAD
查看文件
git diff <file>
git diff
git diff <$id1> <$id2>
git diff <branch1>..<branch2>
git diff --staged
git diff --cached
git diff --stat
查看提交记录
git log
git log <file>
git log -p <file>
git log -p -2
git log
tig
仓库管理
# 初始化一个版本仓库
git init
# Clone远程版本库
git clone git@xbc.me:wordpress.git
# 添加远程版本库origin,语法为 git remote add [shortname] [url]
git remote add origin git@xbc.me:wordpress.git
# 查看远程仓库
git remote -v
# 修改远程仓库地址
git remote set-url origin git@ github.com:robbin/robbin_site.git
# 删除远程仓库
git remote rm <repository>
工作流管理
# 添加当前修改的文件到暂存区
git add .
# 如果你自动追踪文件,包括你已经手动删除的,状态为Deleted的文件
git add -u
# 提交你的修改
git commit –m "你的注释"
# 推送你的更新到远程服务器,语法为 git push [远程名] [本地分支]:[远程分支]
git push origin master
# 查看文件状态
git status
# 跟踪新文件
git add readme.txt
# 从当前跟踪列表移除文件,并完全删除
git rm readme.txt
# 仅在暂存区删除,保留文件在当前目录,不再跟踪
git rm –cached readme.txt
# 重命名文件
git mv reademe.txt readme
# 查看提交的历史记录
git log
# 修改最后一次提交注释的,利用–amend参数
git commit --amend
# 已使用git add .,将修改过的文件a、b加到暂存区,现只想提交a,不想提交b
git reset HEAD b
# 取消对文件的修改
git checkout –- readme.txt
------------------------------扩展一下------------------------------
# 暂存
git stash
# 列所有stash
git stash list
# 恢复暂存的内容
git stash apply
# 删除暂存区
git stash drop
分支管理
git br -r
git br <n_br>
git br -v
git merge <br>
git br --merged
git br --no-merged
git co <br>
git co -b <n_br>
git co -b <n_br> <brh>
git co $id
git co $id -b <n_br>
git br -d <br>
git br -D <br>
------------------------------远程分支------------------------------
git pull
git pull --no-ff
git fetch or
git merge or/master
git co --track or/br
git push
git push or master
git push -u or master
git push origin <lo_br>
git push origin :<re_br>
补丁管理
git diff > ../sync.patch # 生成补丁
git apply ../sync.patch # 打补丁
git apply --check ../sync.patch # 测试补丁能否成功
# 方便在多台机器上开发同步时用