简体   繁体   English

我最近的提交有效。 我当前的工作集有一个错误。 如何找出导致该错误的更改?

[英]My most recent commit works. My current working set has a bug. How do I find out what change caused the bug?

A change I've made since the latest commit has introduced a bug.自最新提交以来我所做的更改引入了一个错误。 I've read through the diff (between the latest commit and my presently uncommitted working set) a thousand times, and can't for my life figure out what change has introduced this bug.我已经阅读了差异(在最新提交和我目前未提交的工作集之间)一千次,但我一生都无法弄清楚是什么变化引入了这个错误。 How can I use git to find out which change caused the bug to appear?如何使用 git 找出导致错误出现的更改?

git cannot help you here, since you just have a big (?) heap of changes that aren't even committed. git在这里帮不了你,因为你只有一大堆(?)甚至没有提交的更改。 You could however (ab)use git to help you find the mistake:但是,您可以 (ab) 使用git来帮助您找到错误:

Commit your changes in small commits that are functional (probably you'll already find your problem when doing this).在功能性的小提交中提交您的更改(可能您在执行此操作时已经发现了问题)。 I'd recommend using git add -p to stage only part of your developments, something like:我建议使用git add -p来仅git add -p部分开发,例如:

git add -p
# select some minor changes that make up one small working commit
git commit -m "first working changes"
git stash # move all other changes aside in a git stash
# now test if your code still works, if it does, you can continue:
git stash pop # put the stashed changes back
# repeat the previous actions.

This will help you commit your working changes bit by bit.这将帮助您一点一点地提交您的工作更改。

Supposing you had made many small commits, you could have used git bisect to help you find the faulty commit.假设你做了很多小的提交,你可以使用git bisect来帮助你找到错误的提交。

You can't find it with git since git doesn't know the behavior of your code, it only keeps versions of it.你不能用 git 找到它,因为 git 不知道你的代码的行为,它只保留它的版本。

You can comment out or stash some parts of your work to find the bug.您可以注释掉或隐藏工作的某些部分以查找错误。

For the next time, if the diff is to big you can try to commit more often smaller piece of code so you can revert your commits easily to find a bug下一次,如果差异太大,您可以尝试更频繁地提交较小的代码段,以便您可以轻松地恢复提交以找到错误

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM