Undo the local commits
Sometimes we realize that there is some error /mistake but by that time a few of the changes are committed locally.
git reset HEAD-2 // undo last 2 commits and keep changes
git reset --hard HEAD-2 // undo last two Commits,discard changes
Remove a file from GIT without removing it from the file system
If you are not careful, you may add some unnecessary files during git add.
If you try to use git rm, it will remove the file from both the staging area as well as the file system.
git reset filename // or git remove --cached filename
echo filename >> .gitignore // add it to .gitignore to avoid re-adding it
This command removes the staged version only and adds the file to your .gitignore to avoid making the same mistake again.
Common Git Problems and Their Fixes
Git is a free and open-source version control system. These days git is being extensively used and therefore this article focuses on some of the common Git tricks that everybody at some point of time requires while working with git or Github.
Sometimes the user makes some mistakes while working on Git which results in the loss of information or wrong information being added. To overcome this problem, Git provides some methods/tricks to roll back or modify the changes that were made wrong or made by mistake. Some of these problems along with their fixes are listed below:
Table of Content
- 1. Edit a commit message
- 2. Undo the local commits
- 3. Reverting pushed commits
- 4. Avoid repeated merge conflicts
- 5. Find a commit that broke something after a merge