2016-02-19 66 views
0

我正在使用一个开源项目。其实我有一个克隆主,我正在写单元测试。现在在编写单元测试之后,在abc.cxx 中说,我想通过恢复一个提交来检查我的测试是否失败(我有提供实际修复错误的修补程序的提交ID)。如何在恢复提交并保留单元测试时检查测试?

那么通过git命令检查这个最好的方法是什么?我试过git恢复,但我的测试也被删除(在abc.cxx),我无法测试该功能。

我是一个初学者与git和导致任何形式的错误可以导致我重建主(6-7小时)。

+0

构建完成后复制(不复制)您的repo文件夹,然后随副本一起玩。即使你搞砸了,你也有原始的完整。 –

回答

2

我建议:

  1. 提交您的单元测试专用,临时党支部,
  2. 回复的bug修复在这个分支,
  3. 测试你的单元测试,
  4. 如果一切OK,重订/在主合并的单元测试

演示:

# INIT 
$ git init test 
Initialized empty Git repository in /tmp/test/.git/ 
$ cd test/ 
$ echo bug > file 
$ git add file 
$ git commit -m"Commit with bugs in it" 
[master (root-commit) 498680f] Commit with bugs in it 
1 files changed, 1 insertions(+), 0 deletions(-) 
create mode 100644 file 
$ echo feature > file 
$ git commit -am"Fix bug #1" 
[master 05540d3] Fix bug #1 
1 files changed, 1 insertions(+), 1 deletions(-) 

# (1) 
$ echo 42 > unit-test 
$ git add unit-test 
$ git checkout -b unit-test 
A unit-test 
Switched to a new branch 'unit-test' 
$ git commit -m"Add unit test for bug #1" 
[unit-test 240bc6c] Add unit test for bug #1 
1 files changed, 1 insertions(+), 0 deletions(-) 
create mode 100644 unit-test 
$ git l 
* 240bc6c (HEAD, unit-test) Add unit test for bug #1 
* 05540d3 (master) Fix bug #1 
* 498680f Commit with bugs in it 

# (2) 
$ git revert 05540d3 
Finished one revert. 
[unit-test 5f5eb62] Revert "Fix bug #1" 
1 files changed, 1 insertions(+), 1 deletions(-) 
$ git l 
* 5f5eb62 (HEAD, unit-test) Revert "Fix bug #1" 
* 240bc6c Add unit test for bug #1 
* 05540d3 (master) Fix bug #1 
* 498680f Commit with bugs in it 

# (3) 
$ # check for bug 

# (4) 
$ git checkout master 
Switched to branch 'master' 
$ git rebase 240bc6c 
First, rewinding head to replay your work on top of it... 
Fast-forwarded master to 240bc6c. 
$ git branch -D unit-test 
Deleted branch unit-test (was 5f5eb62). 
$ git l 
* 240bc6c (HEAD, master) Add unit test for bug #1 
* 05540d3 Fix bug #1 
* 498680f Commit with bugs in it