git show a8098222d481b2c4249e09cdf639427b237a1d8f
Shows only index.html
changes from the commitgit show a8098222d481b2c4249e09cdf639427b237a1d8f index.html
Shows changes of the last commit (HEAD always points to the last commit if it is not detached)git show HEAD
git log
Lists all commits each on one line (only commit identifier and commit message)git log --pretty=oneline
Almost the same as the above command. But the commit identifier is shortened (only the first several symbols)git log --oneline
If we are on master
and we want to see other branch's commitsgit log another_branch
After fetching new commits from remote, we can see the new commits (even if we are on master
)git log origin/master --oneline
Shows some abbreviated stats for each commitgit log --stat
It shows all commits in the history of branches, tags and other refs, but it does not show commits that are not reachable from any refgit log --all
We can even specify a format of the commits historygit log --pretty=format:"%h - %an, %ar : %s"
Where:
%h
is the commit identifier
%an
- author of the commit
%ar
- how much time ego was created
%s
- message of the commit
The format result: a11bef0 - Scott Chacon, 6 years ago : Initial commit
...
Funny format which will result in:54d459d by VLR, which created the commit 28 hours ago with comment: some messagee
git log --pretty=format:"%h by %an, which created the commit %ar with comment: %s"
git difftool HEAD
Shows the difference between the commits in some of the difftool apps (that is previously configured)git difftool a8098222d481b2c4249e09cdf639427b237a1d8f 17d3352bd6486e4c34bbfc51053c7b86911458da
Shows the difference between login.frm
files from different commits in default diff.toolgit difftool a8098222d481b2c4249e09cdf639427b237a1d8f 17d3352bd6486e4c34bbfc51053c7b86911458da login.frm
If the diff.tool is not configured, the default console diff tool vimdiff
will be used instead.
...
Shows what default diff.tool isgit config --global merge.tool
Shows what meld.path isgit config --global mergetool.meld.path
Configure merge tool and set meld
as defaultgit config --global merge.tool "meld"
git config --global mergetool.meld.path "C:\Program Files (x86)\Meld\Meld.exe"
Configure difftool prompt to falsegit config --global difftool.prompt false
login
branchgit branch -d login
Deletes the login
branch (with force mode, which means - the branch will be deleted, even if it's not fully mergedgit branch -D login
git push origin new_branch
If the branch does not exist on remote repository, first should be run this command:git push --set-upstream origin new_branch
Alternative of the above command is this command:git push -u origin new_branch
To delete branch new_branch
on remote repositorygit push origin new_branch --delete
git diff
Shows staged changesgit diff --staged
The same as the above commandgit diff --cached
Shows the difference between the working directory and index (both staged and unstaged files)git diff HEAD
Shows the difference between the commitsgit diff a80982d 17d3352
Shows the difference between login.frm
files from different commitsgit diff a809822 17d3352 login.frm
.git / HEAD
If the current branch is master and HEAD
is not detached, then the content of the file will be ref: refs/heads/master
detached HEAD
state if the HEAD does not point to the most recent commit.
We can go into detached HEAD
if we run the command below (if the commit is not the last one)git checkout ba48ldo