git TutorialIntroduction Installing Git Understanding Git architecture Initializing the new Git respository Cloning new Git repository .git directory in Git repository Viewing Git configuration First time Git configuration Using SSH keys with Git Checking Git status Adding files into staging area in Git Committing changes to the local repository Ignoring files using .gitignore Viewing the history of commits Viewing the file contents in working directory, staging area and repository Viewing difference between files Viewing the history of files Git revert Git Reset git reflog Creating and switching to new branches in Git Viewing existing branches Merging branches Resolving conflicts Rebase Deleting branches Renaming the branch in Git Push Pull Stashing the changes in Git Tags in Git Patches in Git Creating new repository on GitHub Pushing local repository to remote repository like GitHub IntelliJ IDEA
Commit history in gitGit repository can be considered as a chain of commits as shown in below image. In below image, C1 is the first commit. C2 is the second commit. C2 will point to C1. If we add on more commit say C3, C3 will point to C2. There is special pointer called as HEAD which always points to the currently checked out commit. If you want to view the history of Git commits, you can use below command.
Below image shows that current branch of the repository has 2 commits. For each commit, it shows below information.
- Commit hash id
- Author of the commit
- Time stamp when the commit was made
- Commit message
git log optionsgit log command accepts lot of parameters as mentioned below.
- git log -3 : This shows only last 3 commits
- git log –author=”sagar” : This shows only commits made by specific author say sagar
- git log –after=”2016-06-12 14:37″ –before=”2016-06-12 15:59″ : This shows commits made only between 12 June 2016 14:37 to 12 June 2016 15:59
- git log –all –grep “[abc|xyz]” : shows all commits where commit message matches the given regular expression.
- git log –graph –oneline –decorate –all : shows git history in graphical format
- git log –pretty=oneline : Shows git history in one line per commit
- git log –name-status : shows which files have changed in each commit
- git show –pretty=”format:” –name-only 878sdjhsk8 : shows which files have changed in git in specific commit
Complex problems, Simple Solutions