![]() |
VOOZH | about |
Error searching and handling in Git involves identifying issues in the repository and using appropriate commands to fix, revert, or manage changes efficiently.
These are common mistakes developers face in Git along with their fixes using appropriate commands.
Sometimes files are staged using git add, but you may want to unstage specific files to modify them before committing.
Syntax:
git reset <filename/dirname>π ImageIf you forgot to include some changes in the last commit, you can update it without creating a new commit.
Syntax:
git commit --amendπ ImageAllows you to change the message of the most recent commit without creating a new commit.
Syntax:
git config --global alias.hist 'log --pretty=format:"%C(yellow)%h%Geeks%ad |
%C(green)%s%Geeks%C(blue)%d%for Geeks %C(red)[%an]" --graph --decorate --date=short'π ImageUsed when unwanted files (like personal data) are committed and need to be removed while keeping other files intact.
Syntax:
git reset --mixed HEAD~
git reset --mixed <commit-id>If unwanted changes are made locally, they can be discarded to restore the file to its previous state.
Syntax:
git checkout -- <filename>
git checkout -- <dirname>Removes the last commit while keeping the changes staged so they can be modified and committed again.
Syntax:
git reset --soft HEAD~1Resets the project to a previous state, removing the incorrect commit and its changes.
Syntax:
git reset --hard HEAD~n
git reset --hard <commit-id>Restores the project to a previous state, removing all changes made after that point.
Syntax:
git reset --hard <branch-number-here>Restores a local branch that was accidentally deleted using its reference.
Syntax:
git checkout -b <branch> <sha-keypair>Changes the name of a branch to correct or update it as needed.
Syntax:
git checkout <old_branch_name>
git branch -m <new_branch_name>Reorders or combines commits to organize the commit history more effectively.
Syntax:
git rebase --interactive <commit-id>Note: Works only on local commits, not pushed ones.
Git hooks are scripts that run at specific stages (like before commit) to check code and prevent errors before they are saved.
Example Logic: