我正在处理一个开源项目。事实上,我有一个大师的克隆,我正在编写单元测试。现在,在编写单元测试(例如在abc.cxx中)之后,我想通过恢复commit来检查我的测试是否失败(我有修复错误的修补程序的提交ID )。
那么,通过git命令检查这个问题的最佳方法是什么。我已经尝试过git还原,但是我的测试也被擦除了(在abc.cxx中),并且我无法测试这个函数。
我是一个git的初学者,任何类型的错误都可能导致我的大师的重建(6-7小时)。
发布于 2016-02-19 15:10:48
我建议:
演示:
# 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
https://stackoverflow.com/questions/35507700
复制相似问题