git命令笔记

git -bare init 
git remote add origin ssh://myserver.com/home/git/myapp.git 
git remote show origin 
[receive] 
denyCurrentBranch=ignore 

git diff查看当前修改的和暂存区的差别 
git diff --cached查看暂存区和上次提交的快照之间的差别 
git diff --staged同上(1.6.1以及以上) 

git commit 1.txt -m 'comment' 
git commit -a跳过git add步骤,直接提交 

git rm 1.txt移除文件(前提是文件已经commit) 
(如果手工删除文件,那还需要进行提交) 
git rm -f 1.txt如果要删除时文件已经放入了暂存区,则加-f参数 
git rm --cached 1.txt 在git仓库里删除,但是依然保存当前工作目录里的文件 
(可用于某些误commit) 

git rm log/*.log 注意这里的反斜杠,表示使用git自己的匹配模式,会递归所有, 
如果不加反斜杠,则是以glob模式,不会递归 

git mv file1 file2使用mv进行文件改名操作 
相当于 
mv file1 file2 
git rm file1 
git add file2 

git log 查看提交历史(无参数会列出所有log) 
git log -p -2 -p每次提交的差异 -2最近两次更新 
git log --stat 查看其他协作者提交的更新改动 
--pretty=oneline short full fuller format:"%h - %an,%ar:%s"设置格式 
--graph 以字符图形的方式显示 
--since=2.weeks 
--until 

gitk (在项目的当前目录输入) 

git commit -m 'init commit' 
git add anotherfile.txt 
git commit --amend 
这个提交是从快照里提交的,并且最终的结果是修正补充了第一次的提交 

git reset HEAD 1.txt 取消已经暂存的状态 

git checkout 1.txt 覆盖现有未提交的修改(危险) 


远程仓库 repository [ri'paze'tori] 
git remote 查看当前配置的远程仓库 
git remote -v (verbose) 显示远程仓库详细 
git remote add [shortname] [url] 添加远程仓库 
git fetch [remote-name] 
?? 如果设置了某个分支用于跟踪某个远程仓库的分支,可以使用git pull自动抓取数据下来 
git push [remote-name] [branch-name] 推送 (默认:master origin) 
git remote show [remote-name] 查看远程仓库的信息 
git remote rename [newname] [oldname] 修改名称 
git remote rm origin 删除远端仓库 

git tag 
git tag -l 'v1.3.2.*' 
git tag -a v0.1 -m 'This is the first version' 创建含附注的标签 
git show v0.1 查看相应标签的版本信息 
git tag -s v0.1 -m 'This is the first version' 签署标签(私钥?GPG?) 
git tag v1.1-lw 打轻量级标签 git tag [tag-name] 
对已经提交的打标签 
git log --pretty=oneline 查看校验和 
git tag -a v1.1 43bc345 (带上之前提交的校验和,不用全部,部分就可以了) 
git push origin [tag-name] 将标签推送到服务器 
(默认打的标签是不传送到远端服务器上) 
git push origin --tags 一次推送所有标签 

git branch [branch-name] 创建分支 
git checkout [branch-name] 切换到分支 
git checkout -b [branch-name] 新建并切换到该分支 

git checkout master 转到主分支 
git merge hotfix 将hotfix分支合并到master 
git branch -d hotfix 删除hotfix分支 

合并分支时,如果出现冲突,git作合并,但不会提交,而是等待人工处理冲突。冲突的文件的状态将会是unmerged。手动解决冲突之后,通过git add命令将冲突文件标记为resolved 

git mergetool图形界面的合并工具 

git branch 列出所有的分支清单(列表中带*的表示该分支在当前分支的前面) 
git branch --v 查看各个分支最后一次commit的信息 
git branch --merged 查看哪些分支合并到了当且的分支 
git branch --no-merged 查看未合并的 
git branch --D testingBranch 
如果被删除的分支有未合并的工作,用-d删除会报错,可以用-D强制删除 

原文地址:https://www.cnblogs.com/liqipeng/p/4592170.html