![]() |
VOOZH | about |
Common Git problems arise from mistakes during commits, merges, or file handling, but Git provides commands to fix and manage these issues efficiently.
Editing a commit message fixes mistakes in the latest commit, and --amend updates it by creating a new commit and modifying history.
git commit --amend
git commit --amend -m "New message"If a file was forgotten during git add:
git add forgotten_file_name
git commit --amend👁 ImageIf the commit is not the latest, use interactive rebase:
git rebase --interactive
git rebase --interactive origin branch👁 ImageThis will give the following menu:
👁 ImageNote: Interactive rebase allows full control over commit history, including modifying, merging, or deleting commits before pushing to the remote repository.
Undoing local commits helps fix mistakes made after committing changes but before pushing them to the remote repository.
git reset HEAD-2
git reset --hard HEAD-2👁 Imagegit reset filename
git rm --cached filename
echo filename >> .gitignoreReverting pushed commits helps fix mistakes in commits that are already pushed to the central repository without altering commit history.
git add .
git commit -m "first commit"
git revert -n HEAD👁 ImageNote: Revert does not delete history but creates a new commit that undoes the changes, making it safe for shared repositories.
Avoiding repeated merge conflicts helps save time by reusing previously resolved conflicts during future merges.
git config --global rerere.enabled true👁 ImageGit bisect helps identify the commit that introduced a bug by performing a binary search between good and bad commits.
git bisect start👁 Image
git bisect bad
git bisect good <revision>
git bisect good // OR git bisect bad