A commit 1) in git is an object 2) that stores the information about:
It's added in commit log (or log) behind its parent commit.
For each commit, a new snapshots (tree) of the project directory is preserved.
Commit identifier are the hash object calculated on the following inputs:
To reference a commit by name and not by SHA, named called ref can be used.
HEAD is a special ref that refers to the current branch (ie last commit of the current branch)
The commot message is given with the -m option.
git commit -m "My Commit"
A commit has a:
git cat-file -p fdf4fc3
# where fdf4fc3 is the first characters of the commit hash
# for the last commit
git cat-file -p HEAD
tree d8329fc1cc938780ffdd9f94e0d364e0ea74f579
parent xxxx
author Foo <[email protected]> 1243040974 -0700
committer Bar <[email protected]> 1243040974 -0700
First commit
where:
Just for the last commit
git cat-file -p HEAD
The commit tree is the tree of the commit. It's an image of the file system (ie file and directory)
Get the hash of the commit tree
commitHash^{tree}
# dos: commitHash^^{tree}
For example:
git rev-parse commitHash^{tree}
git ls-tree commitHash^{tree}
git show --pretty="" --name-only commitHash
git ls-tree $(git rev-parse commitHash^{tree})
git rev-parse commitHash:path/to/file
git show commitHash:path/to/file
gitk the commit viewer
gitk file
gitk --follow file # for rename
git commit
The commit-tree 3)is a low level command that permits to creates a commit from a tree
echo 'First commit Message' | git commit-tree d8329f
# d8329f is the tree hash
To visualize the type of commit, you can use emoji. See a list of emoji by commit type at Emojis Commit
What is the Git Log (also known as commit history or commit log) ?
git log --format=fuller
git log --pretty=oneline
Undo the last commit without deleting the changed files - Reset
# --soft is the default
git reset --soft HEAD~
If you accidentally commit on master, it's not hard to fix things up. Assuming you've just made an errant commit on master:
git branch myNewTopicBranch
git reset --hard upstream/master
git commit --amend args
Example:
git commit --amend -m "another commit message"
git commit --amend --date='Wed Feb 16 14:00 2037 +0100' -C HEAD
git reset HEAD~
If you want to your working directory back to the status of upstream, see working directory purge
git log master..branch-X
Options:
git difftool -y origin/master..origin/develop
git checkout commit_hash
git checkout 56a4e5c08
You are then in a detached head state.
or
git checkout -b branchName commitHash
PERIOD_HOURS=4
git log --oneline --since '$PERIOD_HOURS hour ago' | wc -l