新建git 项目
git init
添加文件
git add .
git add *.c
删除文件
git rm file.text (删除文件跟踪)
git rm -f file.test (删除之前添加的记录)
git rm --cached fill.text (仅删除git 不删本地)
移动文件
git mv from_file.test to_file.test
提交添加
git commit -m '注释'
git commit -a -m '注释' // -a 自动添加所有已跟踪过的文件更新(跳过git add)
克隆项目
git clone https/ssh_url
查看项目修改状态(文件)
git status
git status -s 简览
左边暂存区 右边工作区 -- A新添加 M修改过
查看项目修改内容
工作区与暂存区:git diff
暂存区与最后一次提交:git diff --staged / git deff --cached
忽略文件
cat .gitignore
子目录可独立配置
demo:https://github.com/github/gitignore
查看提交历史
git log
git log -p // 显示差异(详细)
git log -p -2 // 显示最近两次提交
git log -stat // 仅显示文件行数差异
git log ----pretty=online // 格式化输出 online / short / full / fuller / format: "%h ...." https://git-scm.com/book/zh/v2/Git-%E5%9F%BA%E7%A1%80-%E6%9F%A5%E7%9C%8B%E6%8F%90%E4%BA%A4%E5%8E%86%E5%8F%B2#pretty_format
git log --since=2.weeks // 最近两周的提交
git log --oneline --decorate // 查看head指向当前所在分支
git log --oneline --decorate --graph --all // 查看分支分叉情况
重新暂存
git commit --amend // 在未完成push之前重新修改提交的文件
取消暂存
git reset HEAD file.txt
撤销修改
git checkout -- file.txt
查看远程仓库
git remote -v
添加远程仓库
git remote add <shortname> https/ssh://url
从远程仓库拉取
git fetch <remote>
clone 的仓库 默认名为 origin
git pull
推送到远程仓库
git push origin master
git push origin v1.5 // 推送指定标签到远程
git push origin --tags // 推送所有标签到远程
git push origin --delete v1.1.1 // 远程删除标签
查看远程仓库
git remote show origin
远程仓库重命名
git remote rename <oldname> <newname>
远程仓库删除
git remote remove <name>
列出标签
git tag
git tag -l '1.8.5*'
创建标签
git tag -a v1.1.1 -m 'test'
git tag v1.1.1 // 轻标签 git show 无信息
git tag -a v1.2.2 <hash> // 为已经提交过的历史添加标签
查看标签内容
git show v1.4
标签删除
git tag -d v1.1.1
创建分之
git branch // 获取当前所有分支列表
git branch -v // 查看分支最后一次提交
git branch --merged / --no-merged // 忽略已经合并/未合并的分支
git branch testing
git branch -b testing // 创建后切换到分支
切换分支
git checkout testing
分支合并
git merge testing
删除分支
git branch -d testing