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 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.
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses
are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!