4.Git使用记录

作者: android_赵乐玮 | 来源:发表于2017-03-21 13:33 被阅读0次

Git使用记录

一、分支合并

1. rebase
git rebase <branch-name>
[解决冲突]
git add .
git rebase --continue
[解决冲突]
git add .
git rebase --continue
...
2. cherry-pick
git cherry-pick <commit-id>
[解决冲突]
git add .
git commit -c  <commit-id>

二、 分支相关

1. 修改远程服务器地址:
git remote set-url origin ​<new_remote_repository_address>

查看远程仓库地址: git remote -v

2. 修改本地分支名:
git branch -m <old-local-branch-name> <new-local-branch-name>
3. 修改远程分支名:
// 1. 重命名远程分支对应的本地分支
git branch -m <old-local-branch-name> <new-local-branch-name>
// 2. 删除远程分支  (前提绑定远程分支, git push - u origin name)
git push origin : <old-local-branch-name>
c. 上传新命名的本地分支
git push origin  <new-local-branch-name>: <new-local-branch-name>

4. 查询所有的远程分支

git branch -r  

三、提交相关

1. 修改上一次commit的提交信息及内容:
  git add .   //无内容追加时可不用add
  git commit --amend -m "New commit message"  //追加提交信息
  // --amend 向上一次提交追加内容
2. 撤销提交 git revert

git revert 撤销 某次操作,此次操作之前和之后的commit和history都会保留,并且把这次撤销作为一次最新的提交

      git revert HEAD                  //撤销前一次 commit
      git revert HEAD^               //撤销前前一次 commit
      git revert <commit-hash>

四、暂存相关

1. 清除暂存文件

方法1:git checkout .
方法2:当方法1不能去除时可使用此方法

   git add .    
   git reset --hard HEAD  

五、日志相关

  • 查询筛选
--按文件名筛选--
git log -p <file-path>     
git log -p app/src/main/AndroidManifest.xml  //例
--按时间筛选--
git log --after=<date> --before=<date>
git log --after=2017-5-8 --before=2017-5-10 //例
--按作者筛选
git log --author=<name>
git log --author=zhaolew //例
--按提交信息筛选
git log --grep=<key_string>
git log --grep=删除 //例
--按提交更改内容筛选
git log -S "<key_string>"
git log -S "MainActivity" //例
--根据提交范围筛选
git log <commit-id>..<commit-id>
git log <branch>..<branch>
git log dev..dev_en // 例   (注意 '..' 没有空格)
  • 查看日志的样式
--查看分支日志层次(有点像AS中的Version Control 的日志样式)
git log --graph --oneline --decorate
--显示每个文件变化的行数
git log --oneline --stat
--查看提交日志的详细信息
git log -p     
--按格式输出日志
git log --pretty=format:"<format-string>"
git log --pretty=format:"%cn committed %h on %cd"   //例

标识符示例

%ad    // 日期
%an  // 作者名
%cn  //提交者姓名
%h  // hash值
%s //commit的描述
%d  //对应的 branch 分支名

更多标识符:https://www.kernel.org/pub/software/scm/git/docs/git-log.html#_pretty_formats


(以下图片来自网络,非作者所作)

2010072023345292.png

相关文章

  • 4.Git使用记录

    Git使用记录 一、分支合并 1. rebase 2. cherry-pick 二、 分支相关 1. 修改远程服...

  • Git使用教程-4.Git状态

    status 接着之前初始化的仓库,我们在MyProject目录下右键打开Git bash,运行git statu...

  • Git安装和常规使用

    1.系统环境准备 2.Gti安装部署 3.Git初始化 4.Git常规使用 1) 创建数据-提交数据 2) Git...

  • 4.git分支

    关于分支的一些命令: 在本地新建一个dev(分支名)分支,并推送至远程

  • 简单五部将本地文件放在github

    1.git init2.git add .3.git commit -m "first commit"4.git ...

  • git 提交修改过的文件

    1.git status2.git add 文件名路径3.git stash -u -k 忽略其他文件4.git ...

  • git命令

    1.git安装 2.ssh配置 3.提交git远程库步骤 4.git 其它命令 5.git分支管理 ​

  • git学习笔记

    一、创建并提交 1.在本地创建分支;2.开发;3.git add .4.git commit -m ‘描述’5.g...

  • IDEA的常用小技巧

    1.跳转 2.列操作 3.代码快速生成 4.Git集成 常用网址:Github 码云 快捷键 ctrl+Al...

  • Git存储原理和敏捷开发

    导读目录 1.为什么要用Git版本控制 2.Git文件结构和存储原理 3.GitFlow分支开发规范 4.Git ...

网友评论

    本文标题:4.Git使用记录

    本文链接:https://www.haomeiwen.com/subject/czsmwttx.html