$ git log —pretty options
email (use email header like From and Subject)
format (*unique) -> should use at actual usage in the development
full (all parts of commit messages)
fuller (like full and includes dates)
medium (most parts of messages)
oneline (commit-ids and subject of messages)
raw (the raw commits)
short (few headers and only subject of messages)
pretty-formats
http://git-scm.com/docs/pretty-formats
relative : relative date value (e.g. 3 days ago)
local : local time zone
iso : ISO 8601 format
rfc : RFC 2822 format
short : YYYY-MM-DD
raw : %s %z
default : by default
format options
%H : commit hash
%h : abbreviated commit hash
%T : tree hash
%t : abbreviated tree hash
%P : parent hashes
%p : abbreviated parent hashes
%an : author name
%ae : author email
%ad : author date (format respects —date=option)
%ar :author date, relative
%cn : committer name
%ce : committer email
%cd : committer date (fromat respects —date=option)
%cr : committer date, relative
%s : subject
%e : encoding
…and more.
*I’ve skipped to describe other options such as %aE, %aN which are respecting .mailmap feature set to make it easier to understand simple usage. if you wanna be clear about those please go http://git-scm.com/docs/git-log
$ git log —pretty=format:”%h - %an, %ar : %s”
“abbreviated hash code” - “author name”, “author date, relative” : “subject”
75579b7 - noidea-author, 3 weeks ago : Story-3238 [Dev] Fix a problem of webview when…
Useful options in the usage of git log
-p: display the patches at each commits
—word-diff: that display the changes by word-by-word.
—stat: that display the metrics which have been updated at each commits.
—shortstat: that display the lines modified/added/removed at each commits.
—name-only: that lists up modified files after displaying commit info.
—name-status: that display modified/added/deleted files.
—abbrev-commit: that display abbreviated commit hash
—relative-date: that display date value relatively such as 3months ago
—graph: that displays the ascii graph along with the history of branch and merge.
Filtered output of git log
-(N) : that display recent N times commits only
—since, —after : restrict to output which you specified by since, after options.
—until, —before :restrict to output which you specified by until, before options.
—author : just only display the commit which your specified input value matches the author entry. $ git log —author “noideaman”
—committer : just only display the commit which your specified input value matches the committer entry. $ git log —committer “noidea”
Examples:
$ git log —pretty=“%h - %s” —author=gitster —since=“2014-12-01″ —before=“2015-03-12″ —no-merges --
*actuall i’m not sure last double dashes what it’s supposed to be…
Redo recent previous commit
$ git commit —amend
this command has used the contents on staging area. if nothing changes right after commit, snapshot should be same as before. you just modify the commit message.
other case, like once you committed something then, you forgot to add particular file which should be committed at previous commit, you can redo following
$ git commit -m “commit message”
$ git add missing-files
$ git commit —amend
these command will create only one commit to local repos. 2nd commit command can redo first commit.
$ git reset HEAD <file> … # for Changes to be committed: meaning staged.
Redo the change which you mad in tracked files.
$ git checkout — <file> … # for Changes not staged for commit: meaning not staged.
*NOTICE: this command wipes your changes completely on the files in working tree. if you just move the changes temporarly, you can use stash or branch which we are going through later on.
*actually, we can redo almost the committed datas to git repo. for instance you can do commit to deleted branches and get obsolete commit by amend option back. However, if you lost not committed changes, you will never get back using git.
Take a look all the differenciation between HEAD*current branch and any topic branch which should be no-merged.
if you wanna see the gap between specific branch and specific branch, you can use <since>..<until> syntax.
$ git log —oneline HEAD..topic_branch
then, you can see every single commits there. each commits can be checkouted to local as a branch when you need to check the differenctiation.
When you need changing a remote’s URL
the git remote set-url command has enabled you to do so.
$ # you need to list up existing remotes in order to get the name of the remote you wanna change.
$ git remote -v
origin [email protected]:USERNAME/REPOSITORY.git (fetch)
origin [email protected]:USERNAME/REPOSITORY.git (push)
$ # it’s time to change your remote’s URL
$ git remote set-url origin [ssh|git|https scheme URLs]
$ # e.g. if you have kinda mediator server such as gerrit to prevent pushing changes to directly remote master. you can utilise this command.
$ git remote set-url origin ssh://${your_account}@gerrit.yourcompany.com[:port]/**/yourrepository.git
$ # then, you need to re-list up your remotes in order to check whether it has been valid one.
$ git remote -v
origin ssh://${your_account}@gerrit.yourcompany.com[:port]/**/yourrepository.git (fetch)
origin ssh://${your_account}@gerrit.yourcompany.com[:port]/**/yourrepository.git (push)
if your internal git representative tool set has self-signed certificate, you need to import it as Always trust one on Key Chain Access tool on Mac. And its certificate should be added to system category. after you’ve imported, you need to relaunch ssh daemon following commands. launchctl command is your buddy in this case.
$ sudo launchctl unload /System/Library/LaunchDaemon/ssh.plist
* ssh daemon should be dead by this.
$ sudo launchctl load -w /System/Library/LaunchDaemon/ssh.plist
* ssh daemon should go alive by this.
Now you can use ssh scheme with self-signed certificate of your tool.
Compare particular file between different branches.
# wanna see the diff of particuar file between branchA and branchB.
$ git diff branchA branchB foo/bar.java
# wanna see the diff of different files between differnent branches.
$ git diff branchC:spam/egg.java branchD:hoge/huga.java
Simulate —dry-run at the merge
$ git merge —no-commit —no-ff ${BRANCH}
* this means although its command creates merge-commit, it will not be committed. But it will merge.
$ git merge —squash ${BRANCH}
*this means, it will be merged not making merge-commit
*after checking dried run merge, you can reset everything using hard option.