Find a weapon for a problem-Git Bisect

Source: Internet
Author: User

Let's say you work on the ' 2.6.18 ' version of the project, but your current code (master) crashes (crash). Sometimes the best way to solve this problem is to manually step back (Brute-force regression) The project history and find out which commit ( Commit) has caused this problem. But Linkgit:git-bisect1 can help you solve this problem better:

$ git bisect start$ git bisect good v2.6.18$ git bisect bad masterBisecting: 3537 revisions left to test after this[65934a9a028b88e83e2b0f8b36618fe503349f8e] BLOCK: Make USB storage depend on SCSI rather than selecting it [try #6]

If you run "Git branch" now, you will find that you are now in "No branch" (Translator Note: This is a state of Git bisect). At this point the branch points to commit: "69543", which is exactly in the middle of "v2.6.18" and "Master". Now in this branch, compile and test the project code to see if it crashes (crash). Assuming it crashes this time, run the following command:

$ git bisect badBisecting: 1769 revisions left to test after this[7eff82c8b1511017ae605f0c99ac275a7e21b867] i2c-core: Drop useless bitmaskings

Now git automatically checks out (checkout) an older version. To do this, use "Git bisect good", "Git bisect bad" to tell git if there is no problem with each checked out version; You can now look at the current checkout version, and you'll find git checking out a version between Bad and good using the binary search method (commit or Revison).

In this project (case), 13 attempts were made to identify the commit that caused the problem (guilty commit). You can use the git show command to view the commit, find out who made the changes, and then write the message to TA. Finally, run:

$ git bisect reset

This will be the state before you (before executing git bisect start).

Note: Git-bisect each time you choose to check out the version, just a suggestion; If you have a better idea, you can also try to choose a different version by hand.

Run: $ git bisect visualize

This will run GITK, which will identify the commit (commit) automatically selected by the "Git bisect" command. You can select an adjacent commit (commit), remember its Sha string value, and check it out with the following command:

$ git reset --hard fb47ddb2db...

Then perform the test, and then execute the "bisect good" or "bisect bad" according to the test results; This is done repeatedly until the problem is identified.

Translator Note: Regarding the branch state after "Git bisect start", the translation is inconsistent with the original text. The original is that "git bisect start" will be created after a branch named "Bisect", but the actual situation is in the "no branch" state.

Find a weapon for a problem-Git Bisect

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.