一、查找提交

(1)git bisect(二分搜索法)

基于任意搜索条件查找特定的错误提交。在排查某个提交版本导致的错误时非常有用。

[root@localhost public_html]# git bisect start   开始搜索
[root@localhost public_html]# git bisect bad 告知GIT那个提交时“坏”的,通常是当前版本
[root@localhost public_html]# git bisect good v2.6.27 告知那个版本提交是“好”的,通常是测试通过版本
之后Git会在范围内将每个修订版本搜索出来,之后你要做的就是缩小排查范围。 最后要告诉Git已经完成
[root@localhost public_html]# git git bisect reset
[root@localhost public_html]# git branch
* master

(2)git blame

此命令告诉你一个文件中的每一行最后是谁修改的和哪次提交做出了变更。

[root@localhost public_html]# git blame -L 1, index.html
0a307160 (tong 2018-02-27 11:52:29 +0800 1) <html>
0a307160 (tong 2018-02-27 11:52:29 +0800 2) <body>
^b4e2a14 (tong 2018-02-27 11:45:23 +0800 3) My website is alive!
0a307160 (tong 2018-02-27 11:52:29 +0800 4) </body>
0a307160 (tong 2018-02-27 11:52:29 +0800 5) </html>

(3)Pickaxe

git log -Sstring根据给定的条件沿着文件的差异历史搜索。通过搜索修订版本间的实际差异,这条命令可以找到那些执行改变的提交。

[root@localhost public_html]# git log -Shtml --pretty=oneline --abbrev-commit index.html
0a30716 This is new html!

二、查看提交历史

[root@localhost public_html]# git log
commit aa431d938e85445f6c22c7389a37349f587d5b01
Author: tong <tongxiaoda@anzhi.com>
Date: Tue Feb 27 13:06:21 2018 +0800 mv bar to foo commit 1ed9a862e62bd5513021838cb435cf8170e2173d
Author: tong <tongxiaoda@anzhi.com>
Date: Tue Feb 27 13:04:37 2018 +0800 new bar commit 19a473c2e935efa59b8edea19d2d12be96987a97
Author: tong <tongxiaoda@anzhi.com>
Date: Tue Feb 27 12:00:03 2018 +0800 Remove a poem commit 5be473e1ed6d04ed9e96b7fa3e9e2860607cbd31
Author: tong <tongxiaoda@anzhi.com>
Date: Tue Feb 27 11:59:16 2018 +0800 add poem.html commit 0a3071601cc10777e271a952ead46cffba233e24
Author: tong <tongxiaoda@anzhi.com>
Date: Tue Feb 27 11:52:29 2018 +0800 This is new html! commit b4e2a14de84d29ea8890a2e19f039eb08bc2fc7d
Author: tong <tongxiaoda@anzhi.com>
Date: Tue Feb 27 11:45:23 2018 +0800 Initial contents of public_html

可以用 --graph 选项,查看历史中什么时候出现了分支、合并。

[root@localhost public_html]# git log --oneline --graph
* aa431d9 mv bar to foo
* 1ed9a86 new bar
* 19a473c Remove a poem
* 5be473e add poem.html
* 0a30716 This is new html!
* b4e2a14 Initial contents of public_html

可以用 '--reverse'参数来逆向显示所有日志。

[root@localhost public_html]# git log --reverse --oneline
b4e2a14 Initial contents of public_html
0a30716 This is new html!
5be473e add poem.html
19a473c Remove a poem
1ed9a86 new bar
aa431d9 mv bar to foo

如果只想查找指定用户的提交日志可以使用命令:git log --author

[root@localhost public_html]# git log --author=tong --oneline -3
aa431d9 mv bar to foo
1ed9a86 new bar
19a473c Remove a poem

如果你要指定日期,可以执行几个选项:--since 和 --before,但是你也可以用 --until 和 --after。

--no-merges 选项以隐藏合并提交

[root@localhost public_html]# git log --oneline --before={3.weeks.ago} --after={2018-01-01} --no-merges

三、更改提交

git reset命令会把版本库和工作目录改变为已知状态,其调整HEAD引用指向给定的提交,默认情况下还会更新搜索引以匹配该提交。

git reset-soft

将HEAD引用指向给定提交,索引和工作目录内容保持不变。

git reset--mixed(默认模式)

将HEAD指向给定提交,索引内容也跟着改变以符合给定提交的树结构,但工作目录中的内容保持不变。

git reset-hard

将HEAD指向给定提交,索引内容也跟着改变以符合给定提交的树结构,工作目录内容也随之改变以反映给定提交表示的树的状态。

简单地重做或清除分支上的最近提交

[root@localhost ~]# cd test
[root@localhost test]# git init
Initialized empty Git repository in /root/test/.git/
[root@localhost test]# echo foo >> master_file
[root@localhost test]# git add master_file
[root@localhost test]# git commit
[master (root-commit) 96a97fb] This is test!
1 files changed, 1 insertions(+), 0 deletions(-)
create mode 100644 master_file
[root@localhost test]# echo "more foo" >> master_file
[root@localhost test]# git commit master_file
[master 8b6ce36] Change master_file
1 files changed, 1 insertions(+), 0 deletions(-)
[root@localhost test]# git show-branch --more=5
[master] Change master_file
[master^] This is test! 假设第二次提交是错的,需要改变一下
[root@localhost test]# git reset HEAD^
Unstaged changes after reset:
M master_file
[root@localhost test]# git show-branch --more=5
[master] This is test!
[root@localhost test]# cat master_file
foo
more foo
执行后Git离开了master_file的新状态,因为重置了索引,所以必须重新暂存你想要提交的修改 [root@localhost test]# echo "even more foo" >> master_file
[root@localhost test]# git commit master_file
[master eaf3fca] new change master_file
1 files changed, 2 insertions(+), 0 deletions(-)
[root@localhost test]# git show-branch --more=5
[master] new change master_file
[master^] This is test! 查看版本库中引用变化的历史记录
[root@localhost test]# git reflog
eaf3fca HEAD@{0}: commit: new change master_file
96a97fb HEAD@{1}: HEAD^: updating HEAD
8b6ce36 HEAD@{2}: commit: Change master_file

使用git cherry-pick提交命令会在当前分支上应用给定提交引入的变更。这并不改变版本库中的现有历史记录,而是添加历史记录。

通常用于版本库中一个分支的特定提交引入不同的分支中,即把维护分支的提交移植到开发分支。

git checkout rel_2.3
git cherry-pick dev~2

使用git revert将引入一个新提交来抵消给定提交的影响。

git revert master~3

修改最新提交

git commit --amend --author "Bob <Bob@test.com>"

GIT使用—提交的查找与变更的更多相关文章

  1. Git撤销提交和修改相关操作

    团队开发中经常遇到错误删除文件,错误提交等情况,那么使用Git该如何正确的进行撤销和恢复呢? 一.增补提交 git commit –C HEAD –a --amend -C表示复用指定提交的提交留言, ...

  2. git操作提交方式

    git代码提交 第一次提交代码 在本地建立一个文件夹用来存储代码,相当于一个仓库进入文件夹目录输入下面命令 echo "# xxx" >> README.md (添加一 ...

  3. Git-Runoob:Git 查看提交历史

    ylbtech-Git-Runoob:Git 查看提交历史 1.返回顶部 1. Git 查看提交历史 在使用 Git 提交了若干更新之后,又或者克隆了某个项目,想回顾下提交历史,我们可以使用 git ...

  4. 【第八篇】- Git 查看提交历史之Spring Cloud直播商城 b2b2c电子商务技术总结

    ​ Git 查看提交历史 Git 提交历史一般常用两个命令: git log 在使用 Git 提交了若干更新之后,又或者克隆了某个项目,想回顾下提交历史,我们可以使用 git log 命令查看. 针对 ...

  5. 如何避免git每次提交都输入密码

    在ubuntu系统中,如何避免git每次提交都输入用户名和密码?操作步聚如下:1: cd 回车: 进入当前用户目录下:2: vim .git-credentials (如果没有安装vim 用其它编辑器 ...

  6. 如何利用git shell提交代码到github

    在很早之前我根据找到的一些资料以及自己的实践总结了一篇如何将VS2015上的代码上传到GitHub上,后来我发现有小伙伴私信我,说跟我上面写的不一样,但是那段时间也比较忙,当我发现有人私信的时候差不过 ...

  7. GIT入门笔记(20)- git 开发提交代码过程梳理

    git开发提交流程新项目开发,可以直接往master上提交老项目维护,可以在分支上修改提交,多次add和commit之后,也可以用pull合并主干和本地master,解决冲突后再push 1.检出代码 ...

  8. git 本地提交代码到 github 远程库,没有弹框 github login

     git 本地提交代码到 github 远程库,没有弹框 github login:  原因: win10 有个凭据管理器,给保存了历史登陆用户名密码,导致无法切换用户. 解决办法: 删除历史登陆用户 ...

  9. git 命令提交项目到github

    git 命令提交项目到github步骤如下: 1.使用git 命令客户端进入项目根路径,输入 git init  命令,创建github本地根目录 2.把文件加入到本地项目 git add .  ,如 ...

随机推荐

  1. JZOJ.5289【NOIP2017模拟8.17】偷笑

    Description berber走进机房,边敲门边喊:“我是哔哔”CRAZY转过头:“我警告你,哔哔刚刚来过!”“呵呵呵呵……”这时,哔哔站了起来,环顾四周:“你们笑什么?……”巧了,发出笑声的人 ...

  2. [SCOI2010]序列操作[分块or线段树]

    #include<cstdio> #include<iostream> #define lc k<<1 #define rc k<<1|1 using ...

  3. Android之內置、外置SDCard

    From:http://blog.csdn.net/u011290399/article/details/10363881 在项目中,发现通过Android提供的API获取外置SDCard的操作一直不 ...

  4. Docker修改时区

    简介 docker容器打日志时间滞后8小时 方法 启动时修改时区 Docker修改默认时区 已启动的容器修改时区 进入容器docker exec -i -t [CONTAINNER] /bin/bas ...

  5. 160503、onunload、onbeforeunload事件详解

    最近项目中做到一个功能:在上传页面用户开始上传文件之后用户点击任意跳转都需要弹出提示层进行二次确定才允许他进行跳转,这样做的目的是为了防止用户的错误操作导致这珍贵的UGC 流失(通常用户在一次上传不成 ...

  6. 临时修改当前crontab编辑器

    EDITOR=viexport EDITOR然后crontab -e就不会有这个问题了

  7. sql server dba概念系列引用

    原文转自:https://www.cnblogs.com/gaochundong/p/everyone_is_a_dba_sqlserver_architecture.html <人人都是 DB ...

  8. (3.9)常用知识-标识值(identity)的不连续与强行插入、计算列

    概念:标识值 identity(begin,add_number) 是一种特殊的值,依赖于列,由sql server自动维护,是自增的,而且一般是不会重复的.但是sql server并不维护标识(id ...

  9. 发现一个小技巧:火狐浏览器对phpmyadmin支持更友好

    这段时间ytkah正在迁移服务器(A→B),为了方便起见,直接用phpmyadmin导入数据库.一般我们是用navicat来操作数据库的,但是服务器A设置了权限,无法用navicat连接,只好在浏览器 ...

  10. 使用CocoaPods管理第三方类库[效率]

    项目文件夹   加入第三方框架后的项目文件夹例如以下图 为什么要用Cocoapods?   iOS开发中经常使用的第三方库,比方: 1.FMDB:在使用SQLite是仅仅须要加入libsqlite3. ...