git tips
I'll show some tips like usage, configuration and thought of mine for git.
First of all, it's better to configure aliases with with ~/.gitconfig based on ~/gitconfig because I'll notate with my aliases of git sub-commands.
To see diff to previous commit
All commits of git are node of linked list which has parent node apart from initial commit. Merged commit has two parents. It's easy to learn for programmers =)
git diff HEAD^
shows diff b/w HEAD and its previous commit.
HEAD is current commit you are at and one of nodes for a linked list.
HEAD^
shows the parent commit.
Staging, unstaging and commit
To add all unstaged changes, git add -u
To revert all changes in stage, git reset .
To commit all changes, git ci -am <commit log>
Branching
Easy branching. git co -b spike
This is a shorthand of blew commands.
git branch spike
git checkout spike
If you want a branch which its old history is dropped, you can use --orphan
option.
git co --orphan new-history
It makes a new branch which all files are staged.
If you commit them, simply git ci -m "initial commit"
, The new history will start.
Squash merge
git merge --squash a-spike
takes all changes of a-spike into the current branch and let them be on stage like --orphan
option.
If you commit as is, you can shrink the changes at one commit.
Arrangement of history with rebase --interactive
rebase --interactive
is so powerful command to modify your commit history,
but it may let you miss your important commit and get confused
if you don't know right way to use the command.
I recommend you can use rebase -i
before push your commits to remote repository like github
in order to refine commit log until you get used to rebase
command.
~/.gitconfig
As ~/.gitconfig, you can make your git settings. For example, this is mine.
[alias]
ci = commit
st = status
co = checkout
br = branch
lg = log --graph --pretty=format:'%Cred%h%Creset - %an - %C(yellow)%d%Creset %s %Cgreen(%cr)%Creset' --abbrev-commit --date=relative
sb = show-branch
diffst = diff --stat=200,100
[user]
email = xxxxxxxx@xxxxxxxxxxxx
name = Tomotaka Sakuma
[color]
status = auto
branch = auto
tag = auto
commit = auto
diff = auto
interactive = auto
ui = auto
[github]
user = tmtk75
token = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx