git reset --soft HEAD~1
Explanation: Reverts the most recent commit but keeps your changes in the working directory, letting you make adjustments before re-committing.
git checkout -- <file>
Explanation: Reverts uncommitted changes in the specified file back to the last committed state. Replace <file>
with .
to discard all changes.
git branch -d branch_name
Explanation: Deletes the local branch branch_name
if it has been merged. Use -D
to force delete.
git reflog
git checkout -b branch_name <commit_hash>
Explanation: Finds the last commit on the deleted branch with reflog
, then recreates the branch using the commit hash.
git commit --amend
Explanation: Opens the last commit in your editor to change the commit message or add new changes to it.
git diff
Explanation: Displays differences between your working directory and the last commit, showing what has been changed.
git rm --cached <file>
Explanation: Stops tracking <file>
in Git, but keeps it in your local directory.
git fetch origin
git reset --hard origin/main
Explanation: Syncs your local branch with the remote version, discarding all local changes.
git checkout branch_name -- <file>
Explanation: Pulls only the specified file from branch_name
into your current branch.
git log --author="Author Name"
Explanation: Filters commit history to show only commits by the specified author.