Git provides an option to keep a track on our project progress from revisiting older commits to mending our mistakes and undoing changes. It gives the user to option to review his/her work. Following commands performs similar function.
git revert: As the name suggests, this command is used to return some existing commits. This command introduces a new commit to reverse the effect of some previous faulty commit. This option does not move branch ref pointers to the faulty commit instead inverse the changes from that commit and create a new revert commit. In such a way, project history is maintained. But to execute this command your working tree should be clean.
git revert options:
- -e or –edit: This option let you edit commit message prior to committing the revert. It is the default option.
- –no-edit: Using this option will not start commit text editor.
- -n or –no-commit: Using this option add inverse changes to staging index and working tree instead of making new commits.
git reset: It resets current head to specified state. This git command is not commonly used to it’s restrictive use. It has three basic Option namely, –soft, –hard and –mixed.
git rm: This command is used to remove the tracked file from index or from working tree and git index. It cannot remove files just from working directory. The files removed must be identical to those in current head.
git rm options:
- (files) …: It specifies the files to be removed. There can be an individual file or list of files separated by space character.
- -f or –force: It overrides up-to-date check to ensure files in head matches those in working directory and staging index.
- -n or –dry-run: It does not remove files but instead tell which files would be removed by executing rm command.
- -r: This command allows recursive removal when leading directory name is given.
- – -: This option can be used to separate command-line options from the list of files. It is useful when filenames might be mistaken for command-line options.
- -q –quiet: This option suppresses the output. It normally outputs one line for each removed file.
- –cached: This option is used only when we have to remove file from staging index. Working tree files will be left alone.
Summarizing: We have learnt that git revert is an safer option to undo changes as instead of deleting commit history. It creates a new commit that inverses the changes and git reset, on the other hand, it is a difficult option for undoing changes. The git rm is used to remove the file from the repository, so these are some of the most commonly used commands for undoing changes.
- How to Prepare For Google Summer of Code - A Complete Guide
- How to execute AngularJS controller function on page load ?
- How to use Explode effect in jQuery ?
- What is the purpose of "role" attribute in HTML ?
- Difference between console.dir and console.log
- How to universally parse JSON into blocks using jQuery ?
- CSS | scrollbar-width Property
- HTML5 | MathML <mtr> Tag
- if/else condition in CSS
- HTML5 | MathML <mth> Tag
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.