git学习--githug40-50

githug40-50关学习记录
41、
Name: rebase_onto
Level: 41
Difficulty: **
You have created your branch from wrong_branch and already made some commits, and you realise that you needed to create your branch from master. Rebase your commits onto master branch so that you don’t have wrong_branch commits.
Answer: git rebase –onto master wrong_branch readme-update
注:将readme-update 的基变到master上去,编辑操作参考https://git-scm.com/docs/git-rebase
42、
Name: repack
Level: 42
Difficulty: **
Optimise how your repository is packaged ensuring that redundant packs are removed.
Answer: git repack -d 参考https://git-scm.com/docs/git-repack
43、
Name: cherry-pick
Level: 43
Difficulty: *
Your new feature isn’t worth the time and you’re going to delete it. But it has one commit that fills in README file, and you want this commit to be on the master as well.
Answer: 先用git log 找出对README 的最后一次修改的hashcode,然后在master分支上执行git cherry-pick hashcode
注:关于cherry-pick的用法及说明,可以参考
http://backlogtool.com/git-guide/cn/stepup/stepup7_4.html
https://git-scm.com/docs/git-cherry-pick
44、
Name: grep
Level: 44
Difficulty: **
Your project’s deadline approaches, you should evaluate how many TODOs are left in your code
Answer: git grep -c TODO
45、
Name: rename_commit
Level: 45
Difficulty: *
Correct the typo in the message of your first (non-root) commit.
修改第一次提交的错误信息;步骤有5个,
Answer:
1、先通过git log 找出错误信息在第几次提交,
2、通过 git rebase -i HEAD~2
3、后有个编辑界面,将错误信息所在的那个提交中的pick修改为edit,保存并退出
4、之后执行git commit –amend 修改提交的错误信息
5、然后再执行 git rebase –continue 完成修改
注:关于git rebase的操作参考https://git-scm.com/book/zh/v2/Git-%E5%B7%A5%E5%85%B7-%E9%87%8D%E5%86%99%E5%8E%86%E5%8F%B2
46、
Name: squash
Level: 46
Difficulty: **
You have committed several times but would like all those changes to be one commit.
将好多次提交压缩为一次提交,有以下几个步骤;
Answer:
1、git rebase -i HEAD~4
2、在弹出的编辑框内将update 前面的pick 改为squash 保存并退出
3、在弹出的编辑框内填写提交备注,保存并退出
47、
Name: merge_squash
Level: 47
Difficulty: *
Merge all commits from the long-feature-branch as a single commit.
说明:将long-feature-branch 上的所有提交都merge到master分支上,并只作为一次提交
Answer:
1、git merge –squash long-feature-branch
2、如果没有出现冲突的话,git commit -m ‘add file3’ 即可
48、
Name: reorder
Level: 48
Difficulty: **
You have committed several times but in the wrong order. Please reorder your commits.
Answer: git rebase -i HEAD~2 在弹出的编辑框内调整提交的顺序,然后保存并退出
49、
Name: bisect
Level: 49
Difficulty: *
A bug was introduced somewhere along the way. You know that running ruby prog.rb 5 should output 15. You can also run make test. What are the first 7 chars of the hash of the commit that introduced the bug.
在使用这个命令之前先来介绍一下git bisect 的作用吧,个人感觉这篇文章比较通俗,实用性也比较强:http://smilejay.com/2013/01/git-bisect/
Answer: git bisect 通过二分查找来找出bug最早出现的那次commit,既然是二分查找就是设置头和尾,使用bisect就是设置good 和 bad,
下面让我们一步一步找出这个关卡中出现bug的commit id;
1、首先通过git log 找出这个关卡中开始的commitId和最后的commitId;
2、git bisect start;
3、git bisect good f608824
4、git bisect bad 12628f4
第四步执行完以后会出现以下信息:
Bisecting: 9 revisions left to test after this (roughly 3 steps)
[fdbfc0d403e5ac0b2659cbfa2cbb061fcca0dc2a] Another Commit
这里就是你中间的那次commitId,然后把这次commit 签出来,测试代码,查看测试结果是否正确
5、git checkout fdbfc0d4
6、ruby prog.rb 5 输出结果 15 是预期的结果
7、git bisect good
Bisecting: 4 revisions left to test after this (roughly 2 steps)
[18ed2ac1522a014412d4303ce7c8db39becab076] Another Commit
重复5、6步骤根据输出的结果输入git bisect good/bad 直到最终出现以下结果
18ed2ac1522a014412d4303ce7c8db39becab076 is the first bad commit
commit 18ed2ac1522a014412d4303ce7c8db39becab076
Author: Robert Bittle guywithnose@gmail.com
Date: Mon Apr 23 06:52:10 2012 -0400

Another Commit

:100644 100644 917e70054c8f4a4a79a8e805c0e1601b455ad236 7562257b8e6446686ffc43a2386c50c254365020 M prog.rb
说明:18ed2ac1522a014412d4303ce7c8db39becab076 is the first bad commit 这个就是出现bug的那次提交;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值