C++ 如何在恢复提交和保留单元测试的同时检查测试?

C++ 如何在恢复提交和保留单元测试的同时检查测试?,c++,git,unit-testing,software-design,C++,Git,Unit Testing,Software Design,我正在从事一个开源项目。实际上我有一个master的克隆,我正在编写单元测试。现在在abc.cxx中编写单元测试后 我想通过恢复提交来检查测试是否失败(我有实际修复bug的补丁的提交ID) 那么,通过git命令检查这一点的最佳方法是什么呢。我尝试过git revert,但我的测试也被删除(在abc.cxx中),我无法测试该函数 我是git的初学者,任何类型的错误都可能导致我重建master(6-7小时)。我建议: 在专用的临时分支中提交单元测试 恢复此分支中的错误修复 测试你的单元测试 如果一切

我正在从事一个开源项目。实际上我有一个master的克隆,我正在编写单元测试。现在在abc.cxx中编写单元测试后 我想通过恢复提交来检查测试是否失败(我有实际修复bug的补丁的提交ID)

那么,通过git命令检查这一点的最佳方法是什么呢。我尝试过git revert,但我的测试也被删除(在abc.cxx中),我无法测试该函数

我是git的初学者,任何类型的错误都可能导致我重建master(6-7小时)。

我建议:

  • 在专用的临时分支中提交单元测试
  • 恢复此分支中的错误修复
  • 测试你的单元测试
  • 如果一切正常,在master上重新设置/合并单元测试
  • 演示:

    我建议:

  • 在专用的临时分支中提交单元测试
  • 恢复此分支中的错误修复
  • 测试你的单元测试
  • 如果一切正常,在master上重新设置/合并单元测试
  • 演示:

    在生成后复制(而不是克隆)您的repo文件夹,然后再使用该副本。即使你搞砸了,你也可以原封不动地复制(而不是克隆)你的repo文件夹,然后再复制。即使你搞砸了,你的原作也完好无损。
    # 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