GIT 常用命令(一)

2018-12-31  本文已影响0人  RonZheng2010

git clone

克隆指定的repository。-b选项可以指定一个分支。

git clone <repository> -b <branchname>

创建一个裸库以便发布给其他人

git clone --bare <repository> <directory>

git branch

创建分支,跟踪指定的远端分支start-point

git branch [--track] <branchname> <start-point>
# example
git branch --track develop origin/develop

显示分支的名字,最后一次提交,跟踪的远端分支名

git branch -vv

分支重命名

git branch -m <oldname> <newname>

git checkout

切换到指定分支。-b 要求先创建它。

git checkout [-b] <branchname>

git status

-s 指定以短格式输出。

git status [-s]

git tag

创建标签。-a指定创建含附注类型的标签。commit是创建标签的点。

git tag -a <tagname> -m "message" <commit>

git diff

git diff

缺省的不带参数的情况,从stage到工作目录的修改

git diff --cache

--cache,从HEAD到stage的修改

git diff <commit1>...<commit2> 

比较commit1到commit2的修改

git merge

--no-ff指定用非快进方式合并分支,得到“钻石形“提交树。

git merge --no-ff <branch>

git rebase

用git merge合并分支时,如果主干上已有其他人的提交,得到的可能是“波浪形”的树,而不是“钻石形”的。

这时可以先用git rebase改变分支的起点,再用git merge合并。这样就能得到“钻石形”的树了。

git rebase --onto <new-base> --root

git rebase的工作是:把分支branch上的节点,依次重新提交到新起点new-base。

git rebase --onto <new-base> <upstream> <branch>

git reset

如果最近的有些修改不要了,并且这些修改还没有push到服务器,可以用git reset退回到修改前的点

git reset < --soft | --mixed | --hard > <commit>

--mixed只丢弃暂存区,但工作目录中的修改仍然保留, --hard是连工作目录的修改一并清除。

git revert

如果最近的有些修改不要了,但这些修改已经push到服务器,就不能用git reset了。只能用git revert,这实际上是生成了逆向的修改。

git revert <commit>

<commit>是要被逆向的修改。

git cherry-pick

需要分支上的某些修改,而不是全部,使用git cherry-pick

git cherry-pick <commit>

<commit>是要合并的修改。

git reflog

显示被抛弃的commit,这些commit不在任何分支上。git reflog不需要参数。

git remote

-v显示远程仓库的名字和URL

git remote -v

列出远程仓库的 URL 与跟踪分支的信息

git remote show <remote-name>

git fetch

从远程仓库拉取所有你还没有的数据。 执行完成后,你将会拥有那个远程仓库中所有分支的引用,可以随时合并或查看。

git fetch

git pull

自动的抓取远程分支,然后合并到当前分支

git pull

git push

将 本地分支推送到服务器

git push

git stash

将当前的修改存入git的本地栈中,以待后面恢复。

git stash 

查看本地栈中的stash列表。

git stash list
stash@{0}: WIP on master: 049d078 added the index file
stash@{1}: WIP on master: c264051 Revert "added file_size"

将栈中的stash弹出并应用。

git stash pop

也可以删除指定的stash。

git stash drop stash@{0}

相关链接

GIT 常用命令(一)
GIT 常用命令(二)
GIT 概念和配置
【转】一个成功的 Git 分支模型

参考资料

git-stash用法小结
https://www.cnblogs.com/tocy/p/git-stash-reference.html

上一篇 下一篇

猜你喜欢

热点阅读