Open In App

Git- Debugging

Improve
Improve
Like Article
Like
Save
Share
Report

Like traditional word editors, we cannot undo changes simply. We have various git commands available to debug and undo changes. We will discuss such commands in this article.

git bisect: This command uses the binary search algorithm to find out the commit that introduced a bug. It is used by first telling it “bad” commit i.e. commit that is known to contain bug and “good” commit that is known to be before bug was introduced. Then git bisect picks a commit from “bad” commit and ask whether the selected commit is good or bad and runs until the “good” commit is reached.

How it works?

  • git bisect start: It start up the git bisect wizard.
  • git bisect bad “version”: It let the git bisect wizard know of a bad commit.
  • git bisect good “version”: It let the git bisect wizard know of a good commit.

After the following set of commands, git selects the commit in the middle range, checks it and return output.

Note: In this image, we have not mentioned any version of git bisect bad and git bisect good, so when we don’t mention any version, the current version is taken by default.

git bisect options:

  • git bisect reset: After one complete bisect session, git bisect reset command is used to return to original head.
  • To undo the change of state: Sometimes, rather than finding a bug in commit bisect command it can also be used to switch the previous state. So it can be used when we are looking to commit that caused a change between “old” and “new” state.

    How it works?
    Instead of bad and good, old and new are used respectively.

    • git bisect start
    • git bisect old “revision”
    • git bisect new “revision”
  • git bisect log: After good and bad revisons, this command is used to get overview of the work done.
  • git bisect skip “version1”..”version2″: It is used to skip a range of commits. It implies no commit ranging from version1 upto version2 should be tested.

git clean: The git clean command is used to delete untracked files from git project. This command completely removes files from the working tree and cannot be recovered again. So this command should be carefully used.

git clean options:

  • -n or –dry-run This command does not remove files, but it is a dummy command which tells what would be actually done. It is used to test run.
  • -f or –force This command remove files from the current directory. This is a necessary command unless clean.requireforce configuration is set to false.
  • -d This command removes untracked directories along with untracked files.
  • -i or –interactive As the name suggests, it is an interactive command that tells what has to be done.

Interactive Mode: It is the command loop which displays the available sub commands.

  • clean: This command deletes untracked directories/files at the point.
  • filter by pattern: We can input a pattern such as *_ to exclude files/directories from deletion. For eg: “*.py” will exclude mentioned file extension from deletion.
  • select number: This command allot a number to untracked files/directories to be deleted. We can also make multiple selection. For Example:
    • “3-5” deletes file number “3, 4, 5”.
    • “3-5, 8, 9” deletes “3, 4, 5, 8, 9”.
    • “3-” deletes file numbers starting from 3 to the last file number.
    • “*” deletes everything.
  • ask each: This will ask one by one to delete the particular file or not.
  • quit: This option lets you to exit without deleting.

Last Updated : 30 Sep, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads