From e29573470f0bb7194bfb7a37e737f83ae6abd238 Mon Sep 17 00:00:00 2001 From: xueweihan <595666367@qq.com> Date: Sat, 16 Jul 2016 17:59:22 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BF=BB=E8=AF=91=EF=BC=8C=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=EF=BC=8C=E5=88=A0=E9=99=A4=EF=BC=9Agit=E6=8C=87=E4=BB=A4(?= =?UTF-8?q?=E6=8C=81=E7=BB=AD=E5=B7=A5=E4=BD=9C)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 129 ++++++++++++++---------------------------------------- 1 file changed, 34 insertions(+), 95 deletions(-) diff --git a/README.md b/README.md index beedb05..ee4968f 100644 --- a/README.md +++ b/README.md @@ -137,13 +137,9 @@ 2. 暂存区:输入命令:`git add 改动的文件名`,此次改动就放到了‘暂存区’ 3. 本地仓库:输入命令:`git commit 此次修改的描述`,此次改动就放到了’本地仓库’,每个commit,我叫它为一个‘版本’ 4. 远程仓库:输入命令:`git push 远程仓库`,此次改动就放到了‘远程仓库’(github等) +5. commit-id: -## Everyday Git in twenty commands or so -```sh -git help everyday -``` - -## Show helpful guides that come with Git +## 展示帮助信息 ```sh git help -g ``` @@ -178,11 +174,6 @@ git diff --cached git diff HEAD ``` -## List all branches that are already merged into master -```sh -git branch --merged master -``` - ## 快速切换分支 ```sh git checkout - @@ -229,39 +220,40 @@ git tag -d git push origin :refs/tags/ ``` -## Undo local changes with the last content in head +## 放弃工作区的修改 ```sh -git checkout -- +git checkout ``` -## Revert: Undo a commit by creating a new commit +放弃所有修改: ```sh -git revert +git checkout . ``` -## Reset: Discard commits, advised for private branch +## 回到某一个commit的状态,并重新增添一个commit ```sh -git reset +git revert ``` -## Reword the previous commit message +## 回到某个commit的状态,并删除后面的commit +和revert的区别:reset命令会抹去某个commit id之后的所有commit ```sh -git commit -v --amend +git reset ``` -## See commit history for just the current branch +## 修改上一个commit的描述 ```sh -git cherry -v master +git commit --amend ``` -## Amend author. +## 查看commit历史 ```sh -git commit --amend --author='Author Name ' +git log ``` -## Reset author, after author has been changed in the global config. +## 修改作者名 ```sh -git commit --amend --reset-author --no-edit +git commit --amend --author='Author Name ' ``` ## 修改远程仓库的url @@ -286,113 +278,65 @@ git branch -a git branch -r ``` -## Stage parts of a changed file, instead of the entire file -```sh -git add -p -``` - -## Get git bash completion -```sh -curl http://git.io/vfhol > ~/.git-completion.bash && echo '[ -f ~/.git-completion.bash ] && . ~/.git-completion.bash' >> ~/.bashrc -``` - ## 查看两个星期内的改动 ```sh git whatchanged --since='2 weeks ago' ``` -## See all commits made since forking from master +## 把A分支的某一个commit,放到B分支上 +这个过程需要`cherry-pick`命令,[参考](http://sg552.iteye.com/blog/1300713#bc2367928) ```sh -git log --no-merges --stat --reverse master.. +git checkout && git cherry-pick ``` -## Pick commits across branches using cherry-pick -```sh -git checkout && git cherry-pick -``` +## 给git命令起别名 +简化命令 -## Find out branches containing commit-hash ```sh -git branch -a --contains -``` +git config --global alias. +比如:git status 改成 git st,这样可以简化命令 -__Alternatives:__ -```sh -git branch --contains -``` - -## Git Aliases -```sh -git config --global alias. git config --global alias.st status ``` -## Saving current state of tracked files without commiting +## 存储当前的修改,但不用提交commit +详解可以参考[廖雪峰老师的git教程](http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/00137602359178794d966923e5c4134bc8bf98dfb03aea3000) ```sh git stash ``` - -__Alternatives:__ +## 保存当前状态,包括untracked的文件 +untracked文件:新建的文件 ```sh -git stash save +git stash -u ``` -## Saving current state including untracked files -```sh -git stash save -u -``` - - -__Alternatives:__ -```sh -git stash save --include-untracked -``` - -## Show list of all saved stashes +## 展示所有stashes ```sh git stash list ``` -## Apply any stash without deleting from the stashed list +## 回到某个stash的状态 ```sh git stash apply ``` -## Apply last stashed state and delete it from stashed list +## 回到最后一个stash的状态,并删除这个stash ```sh git stash pop ``` - -__Alternatives:__ -```sh -git stash apply stash@{0} && git stash drop stash@{0} -``` - -## Delete all stored stashes +## 删除所有的stash ```sh git stash clear ``` - -__Alternatives:__ -```sh -git stash drop -``` - -## Grab a single file from a stash +## 从stash中拿出某个文件的修改 ```sh git checkout -- ``` - -__Alternatives:__ -```sh -git checkout stash@{0} -- -``` - ## Show all tracked files ```sh git ls-files -t @@ -666,11 +610,6 @@ git rebase -i --autosquash git commit --only ``` -## Interactive staging. -```sh -git add -i -``` - ## 展示忽略的文件 ```sh git status --ignored