Git命令大全(Github)

CREAT(创建)

git init                                      在当前目录下创建一个本(Create a new local repository)

git clone  ssh://user@domain.tld/repo.git     在远程库克隆一个本地库(Clone an existing repository)


Configuration(配置)

git config [--global] user.name       设置提交时附带的名字(Set the name attached to all your commits)

git config [--global] user.email        设置提交时附带的email(Set the email attached to all your commits)

git config --global color.ui auto       设置命令行输出回执的颜色(Set colorzition of  command line output for all repos)

git config [--global] user.name         获取当前库设置的用户名(Print set name(in current repository or globally))

git config [--global] user.email        获取当前库设置的email(Print set email(in current repository or  globally))


Local Changes(本地操作)

git status    查看工作区内的文件修改(List changed files in your working directory)

git diff       查看已追踪文件的修改(List changed to tracked files)

git add       添加此文件的所有修改在下次提交时(Add all current changed in file to the next commit)

git add .     添加本地库中的所有修改在下次提交的时(Add all current changed to the next commit)

git mv          修改文件名并添加到下次提交当中(Rename file and add it to next commit)

git rm          删除此文件并将此处删除添加到下次提交当中(Delete file and add its deletion to next commit)    

git commit -a          提交工作区所有文件(Commit all local changes in tracked files)


Commit History(提交历史)

git log                                             显示所有的提交日志(Show all commits)

git log -p                                       这个文件的最后一次提交日志(Shwo changes over time for a specific file)

git log --author=<committer name>  这个提交者最后一次的提交日志(Show changes over time for a specific committer)

git blame <file>                              此文件被谁修改了(Who changed what and when in file)

git stash                                           查看临时的文件变动 (Store changes temporarily)

git stash pop                                    删除上一次记录储蓄新的改动记录(Remove and apply changes)

git rm --cached <file>                  把此文件从过去的提交记录中删除但是保留当前本地的文件(Remvoe file from previous commits but keep it locally)


Branches & Tags(分支和标签)

git branch                                 本地所有的分支列表(List all existing branches)

git checkout <branch>            切换分支(Switch HEAD branch)

git branch <new branch>        创建新分支(Creat a new branch based on your current HEAD)

git branch --track <new-branch><remote-branch>  创建一个新的分支基于一个远程的分支(Creat a new  tracking branch based on a remote branch)

git branch -d <branch>                          删除一个本地分支(Delete a local branch)

git branch origin --delete <branch>       删除一个远程分支(Delete a remote branch)

git push <remote> : <old name>     重命名远程分支名(Rename a branch on remote)git push

 git push <remote> <new name>           

git tag <tag-name>       给当前提交打一个tag,也可以查看当前标签(Tag the current commit)


Update & Publish(更新和提交)

git remote -v                         查看远程库的地址列表(List all currently configured remotes)

git remote show <remote>       查看这个远程库的信息(Show information about a remote)

git remote add <remote> <url> 添加新的远程库(Add new remote repository)

git remote rename <old-name> <new-name>    重命名远程库(Rename a remote)

git fetch <remote>       从远程库更新所有的信息到本地,但是不合并(Download all changes from remote,but don't merge into HEAD)

git fetch -p <remote>     从远程库更新所有的信息到本地,但是不合并并清理已删除的远程分支(Download all changes fromm remote,but don't merge in HEAD and clean up deleted branchs from origin)

git pull <remote><branch>   从远程库更新数据并立即合并数据(Download changes and directly merge into HEAD)

git push <remote><branch>   将本地数据同步到远程库中(Publish local changes on a remote)

git remote add --track <remote-branch><remote><url>  追踪一个远程库(Track a remote repository)

git push --tags                         同步标签到远程库(Publish your tags

git remote show <remote>      显示远程库信息(Show information about a submodule)


Merge & Rebase(分支合并和重整数据)

git merge <branch>       将其他分支和并到当前分支(Merge branch into your current HEAD)

git rebase <branch>          将亲她分支合并到当前分支并按照提交顺序排序(Rebase your current HEAD onto branch)

git rebase --abort             终止当前合并(Abort a rebase)

git rebase --continue       解决冲突后继续当前合并和重整(Continue a rebase after resolving confilcys)

git mergetool                      使用配置的合并工具解决冲突(Resolve conflicts using your configured merge tool)

git add <resolved-file>     手动解决冲突使用编辑器并标记已解决的文件

git rm <resolved-file>


Undo(撤销)

git reset --hard HEAD                丢弃所有的本地修改(Discard all local changes in your working directory)

git checkout HEAD <file>           丢弃此文件的本地修改(Discard local changes in a specific file)

git revert  <commit>                  撤销某次的提交内容(Revert a commit by providing a new commit with contrary changes)

git checkout <commit><file>    撤销某次提交的某个文件的内容(Revert a specific file from a previous commit)


重置头指针到过去的某个提交上,版本回退(Reset your HEAD pointer to a previous commit)

git reset --hard  <commit>     回退到某个版本(Discarding local changes)

git reset <commit>                   回退到某个版本并保存未追踪的改动

git reset --keep <commit>       回退到某个版本并保存未提交的改动

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 194,242评论 5 459
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 81,769评论 2 371
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 141,484评论 0 319
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 52,133评论 1 263
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 61,007评论 4 355
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 46,080评论 1 272
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 36,496评论 3 381
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 35,190评论 0 253
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 39,464评论 1 290
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 34,549评论 2 309
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 36,330评论 1 326
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,205评论 3 312
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 37,567评论 3 298
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 28,889评论 0 17
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,160评论 1 250
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 41,475评论 2 341
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 40,650评论 2 335

推荐阅读更多精彩内容