git stash
:
Explanation:
git stash
temporarily saves changes that are not ready for commit. It's useful when you need to switch branches or deal with unexpected issues.
Usage Example:
git stash # Temporarily saves changes
git stash pop
:
Explanation:
git stash pop
applies the latest stash and removes it from the stash list. It's a convenient way to reapply changes after addressing other tasks.
Usage Example:
git stash pop # Applies the latest stash and removes it
git revert
:
Explanation:
git revert
creates a new commit that undoes the changes introduced by a specific commit. It's a safe way to undo changes without altering the project's commit history.
Usage Example:
git revert <commit_hash> # Creates a new commit to undo changes
git rebase
:
Explanation:
git rebase
is used to rewrite commit history. It moves, combines, or deletes commits, providing a cleaner and more linear history.
Usage Example:
git rebase <base_branch> # Rebases the current branch onto the specified branch
git reset
:
Explanation:
git reset
moves the branch pointer to a specific commit, discarding changes after that commit. It's a powerful command that should be used with caution.
Usage Example:
git reset <commit_hash> # Resets the branch to a specific commit
git clean
:
Explanation:
git clean
removes untracked files from the working directory. It helps keep your project clean by getting rid of files that aren't being tracked by Git.
Usage Example:
git clean -n # Shows a preview of files to be deleted git clean -f # Deletes untracked files
git reflog
:
Explanation:
git reflog
shows a log of all changes to branch references, including resets and rebases. It helps recover lost commits or branches.
Usage Example:
git reflog # Shows a log of branch reference changes
Squash
:
Explanation:
- Squashing commits means combining multiple commits into a single commit. This is often done during an interactive rebase or when merging branches to create a cleaner and more concise history.
Usage Example:
Squashing commits during an interactive rebase:
git rebase -i HEAD~<number_of_commits>
Marking commits with "squash" or "s" allows you to combine them.