- Usages of Git Log
- Git Tags
- Git Stash
- Difference Between Fetch and Pull
- Using Multiple Git Accounts on One Linux System
- Git Cherry-Pick
- Deleting a Commit
- Git Reset — Mixed
- Git Merge — Abort
git log
is a command used to review the history of commits in a repository. It displays the commit ID, author, date, and commit message. You can customize its output using various options, like --oneline
, --graph
, etc., to view the commit history in different formats.
# Basic Log:
git log
# Oneline Log:
git log --oneline
# Graph Log:
git log --graph --oneline
Git tags are references that point to specific points in Git history. They are often used to mark release points (v1.0, v2.0, etc.). There are two types of tags: lightweight and annotated. Annotated tags are recommended for most use cases as they include the tagger name, email, date, and have a tagging message.
- Creating an Annotated Tag:
git tag -a v1.0 -m "Release version 1.0"
- Viewing Tags:
git tag
git checkout tags/v1.0
git stash -u
temporarily stashes changes, including untracked files. It's useful for saving your work-in-progress changes without committing them. git stash pop
applies the stashed changes back to your working directory and removes them from the stash list.
Stash Changes Including Untracked:
git stash -u
git stash pop
git fetch
downloads commits, files, and refs from a remote repository into your local repo, updating your remote-tracking branches. git pull
, on the other hand, not only fetches but also merges the fetched changes into your current branch.
- Fetch:
git fetch origin
- Pull:
git pull origin main
To use multiple Git accounts on one system, configure user-specific details (user.name and user.email) at the repository level. This allows each repo to have its own unique configuration, separate from the global Git configuration.
Set Local Repository Username:
git config user.name "Your Username"
git config user.email "[email protected]"
git config --list
git cherry-pick
is used to apply the changes introduced by some existing commits to the current branch. It's a way to pick and choose individual commits from another branch without merging the whole branch.
- Git Cherry-Pick Commands
git cherry-pick <commit-hash>
To delete a commit, you can use git reset
to move the HEAD to a previous commit and discard changes, or git revert
to create a new commit that undoes the changes of a specified commit.
Reset to Previous Commit (Soft):
git reset --soft HEAD~1
git revert <commit-hash>
Git Reset — Mixed Commands
git reset --mixed
is the default mode for git reset
. It resets the index but not the working tree and changes what is to be committed.
git reset --mixed <commit-hash>
Git Merge — Abort Commands
If a merge results in conflicts, and you decide not to proceed with the merge, you can use git merge --abort
to abort the merge action and return the branch to its pre-merge state.
git merge --abort