g
= git
- Easier to tell what's changed in one line, preferbally in 50 - 72 characters
- Faster code review: no need to read the description or changes to find out what gets changed
- Git commit 50/72 A Note About Git Commit Messages by Tim Pope
- Easier to revert unwanted, published and shared changes by
git revert
- TO BE CONTINUED
Create a new branch based on the development base branch, e.g. develop
and work there. This way:
- Everyone shares a common start point for new features or bug fixes
- Your commits won't influence the shared branch
- You can easily rewrite the history in your own branch without worrying breaking others' code base
Create a branch from the common base point like this:
git checkout -b new-branch `git merge-base one-branch another-branch`
For example, assume the following commits graph, the command above will create the new-branch
based on commit B
.
A --- B --- C one-branch
\
D --- E --- F another-branch
After making all the changes need to be shared, merge this branch from one-branch
and another-branch
.
How I learned Git, mostly.
g help --all
g some-command --help
- Check status
g s
=git status --short --branch
- Check diff
g d
=git diff
- Add changes
- Add file(s)
g a ...
=git add ...
- Partially Add
g ap [...]
=git add --patch
- Add all
g aa
=git add --all
- Do this only when you know what will be added in this commit.
- Add file(s)
- View cached changes
g dc
=git cache --diff
- Commit AND check again when editing commit message
g c
=git commit --verbose
- OR, skip adding, commit all changes
g ca
=git commit --all --verbose
(check again when editing commit message) - (Optional) Check changes in head
g hp
=git show --patch --pretty="tformat:"
YES, I check about 5 times before I commit any changes everytime. And, YES, I use git in command line.
g show branch:file/path
g co branch file/path
= g checkout branch file/path
Use this to revert public and shared commits. It will not mess up your commit history.
Following undos are for commits which are either non-public(un-pushed) or not shared between you and someone else(your own branch).
g co file
= git checkout file
g rs
= g reset
g rs "HEAD^"
= git reset "HEAD^"
Without the ""
zshell will complain.
Use with care. This will also undo all non-staged changes too.
g undo
= git reset --hard
g clean -d -f
g undo [<commit>]
Go to that commit.
The commit
could be a commit in the past, but also one in the "future" (in a remote branch).
For example, assume the following commits graph and local master is one commit behind master.
Running git undo C
on local master will bring the branch up to date, if C is fetched.
A --- B --- C Remote master
\
Local master
g reflog
find out the commit you want to go back, possiblly before an undo.
Every change in git
has a log/commit in reflog
, including reset --hard
. So you can undo almost anything with the help of reflog
.
g undo the-commit
Welcome to 1956 where git does not exist. Just kidding.
g r
= GIT_NO_PAGER=1 git l -10
g ra
= g r --all
g l
~= g log --oneline --graph --format='%C(bold red)%d%Creset %s %C(yellow)%h%Creset'
g la
= g l --all
Result:
* (HEAD -> demo/clean-db-show-the-row, origin/demo/clean-db-show-the-row) HACKY code to show the demo row when status bar is tapped ab9970d
* Clean up database when starting the App for Demo purpose 87503f5
* (origin/develop, develop) Merge branch 'feature/show-last-read-news' into develop 4627487
|\
| * (tag: 1.7.4, origin/feature/show-last-read-news, feature/show-last-read-news) Bump version number 1.3.4/1.7.4, #43 2ddbcb9
| * Extract `didLoadNewsInWebViewWithNewsId` in `RealmNewsViewController`, #43 2b8353d
Original result has color which leads to much better readability. Try the command above to see how actual result look like.
See my .gitconfig
for the real git la
command. The command above is just a approximation.
Thanks for reading. Any feedback is welcomed.