git常用命令

更新本地存储的origin远程上的分支列表

git remote update origin --prune

创建新分支,并切换到新分支

1、基于当前分支创建一个本地分支,没有关联远程分支

git checkout -b [local-branch-name]

2、基于远程分支创建一个本地分支并关联远程分支

git checkout -b [local-branch-name] origin/[remote-branch-name]

3、基于提交创建本地分支,没有关联远程分支

git checkout -b [local-branch-name] [commit]

4、基于tag创建本地分支,没有关联远程分支

git chekcout -b [local-branch-name] [tag]

推送分支

1、推送本地分支到关联的远程分支

git push

2、推送本地分支到远程分支,并建立关联。如果远程没有该分支则会创建一个同名分支

git push -u origin [local-branch-name]

3、推送本地分支到指定的远程分支

git push origin [local-branch-name]:[remote-branch-name]

4、推送到远程同名分支,如果远程分支不存在则创建

git push origin [local-branch-name]

关联远程分支

1、关联远程分支

git branch --set-upstream-to=origin/[remote-branch-name] [local-branch-name]

2、关联远程分支

git push -u origin [local-branch-name]

3、关联远程分支并推送

git push -u origin [local-branch-name]

4、基于远程分支创建一个本地分支并关联远程分支

git checkout -b [local-branch-name] origin/[remote-branch-name]

删除分支

1、删除本地分支

git branch -d [local-branch-name]
git branch -D [local-branch-name]

2、删除远程分支

git push origin :[remote-branch-name]
git push origin --delete [remote-branch-name]

日志查看

git log
git log  按提交时间列出所有的更新,最近的更新排在最上面
常用参数:
-p 选项展开显示每次提交的内容差异
-p -[num] 选项展开显示最近num次提交的内容差异
-[num] 显示最近num次提交的内容差异
--stat 显示简要的增改行数统计
--graph 开头多出一些 ASCII 字符串表示的简单图形,形象地展示了每个提交所在的分支及其分化衍合情况
--since, --after 仅显示指定时间之后的提交。
--until, --before 仅显示指定时间之前的提交。
--author 仅显示指定作者相关的提交。
--committer 仅显示指定提交者相关的提交。
--pretty 使用其他格式显示历史提交信息。可用的选项包括 oneline,short,full,fuller 和 format:后跟指定格式(如下) 【示例: git log --pretty=format:"%an %cd"%H    提交对象(commit)的完整哈希字串
         %h    提交对象的简短哈希字串
         %T    树对象(tree)的完整哈希字串
         %t    树对象的简短哈希字串
         %P    父对象(parent)的完整哈希字串
         %p    父对象的简短哈希字串
         %an    作者(author)的名字
         %ae    作者的电子邮件地址
         %ad    作者修订日期(可以用 -date= 选项定制格式)
         %ar    作者修订日期,按多久以前的方式显示
         %cn    提交者(committer)的名字
         %ce    提交者的电子邮件地址
         %cd    提交日期
         %cr    提交日期,按多久以前的方式显示
         %s    提交说明

代码回退

将某个文件切换到某次提交

git log [file]  查找需要回退到的版本号的commit-id
git reset [commit-id] [file]
git checkout [file]

其他

origin 表示默认远程主机名,一个git资源库可以关联多个远程主机名。添加关联的远程主机名的命令:

git remote add origin2 [git资源库地址]

 

posted @ 2018-09-06 16:35  苏糊  阅读(127)  评论(0编辑  收藏  举报