Git Pro

Git Branching


Tips & Tricks

Git Tools
  • Interactive Staging
    git add -i/--interactive to select some files to stage/unstage
    git add -p/--patch to do partial-file staging
Git Alias

git config --global alias.ci commit
git config --global alias.unstage 'reset HEAD --' : shortcut to unstage a staged file
git config --global alias.last 'log -1 HEAD' : shortcut to get the last commit
git config --global alias.visual '!gitk'
add ! when call external command
git config --global alias.sl '!"C:\Program Files\Sublime Text 2\sublime_text.exe" $*' : add sublime_text to git shortcut


git remote

  • origin is the default name Git gives to the server you cloned from
  • -v : shows the URL that Git has stored for the shortname to be expanded to
  • can pull from many remote repositories, but only the origin remote is a SSH URL and can be pushed to.
  • git remote add [shortname] [url] -> git fetch [shortname]/git pull after git clone -> git push [shortname] [branchname] after git clone
  • git remote show [remotename] : show the remote repository
  • git remote rename [shortname] [newshortname] : rename a reference
  • git remote rm [shortname]: remove a reference to the remote repository

undo things

  • git commit --amend : replace the previous commit
  • git reset HEAD <file> : unstage a staged file
  • git checkout -- <file> : unmodify a modified file dangerous

git log

  • visual tool for git log: gitk
  • -p: shows the diff introduced in each commit
  • -2: limits the output to only the last two entries
  • --word-diff: get word diff instead of normal line by line diff
  • --stat: show abbreviated stats
  • --pretty=oneline/format --graph
  • --pretty=oneline/short/full/fuller
  • --pretty=format:""
Option  Description of Output
%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 e-mail
%ad Author date (format respects the --date= option)
%ar Author date, relative
%cn Committer name
%ce Committer email
%cd Committer date
%cr Committer date, relative
%s  Subject
   ```
> *author: the person who originally wrote the patch*
> *Committer: a person who last applied the patch*


----------------------

`git status`
`git add` : a multipurpose command, use to begin tracking new files, to stage files, and to do other things like marking merge-conflicted files as resolved
##### .gitignore
* `#` as comments
* end with `/` as directory
* `!` to negate a pattern
* `*`: 0+ characters; `?` 1 character; `[0-9]` & `[abc]`
* `**/` as any directory

`git diff` : see what changed but not yet staged
`git diff --cache` or `git diff -staged`: see what staged but not yet committed
`git commit -a` to skip staging area
`git rm` : remove file from working directory and staging area
`git rm --cached` : remove only from staging area
`git mv` : can also do renaming
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 因为原文太长超出字数,Lesson 3 就放在另一篇文章里 How to Use Git and GitHub 标...
    赤乐君阅读 5,272评论 1 5
  • 监测app启动时间 adb shell am start -w [packageName]/[packageNam...
    MrWang915阅读 354评论 0 0
  • git常用命令 GIT常用命令备忘:http://stormzhang.com/git/2014/01/27/gi...
    新篇章阅读 8,611评论 1 26
  • Git常用命令总结Git常用命令总结 git init 在本地新建一个repo,进入一个项目目录,执行git ...
    qui丶MyLove阅读 336评论 0 0
  • 291976-陈国艳《2017-06-16》 【连续第125天总结】 A、目标完成情况 1、抄写概念一遍完成100...
    国艳更文的365天阅读 235评论 0 0