-
关联远程仓库
$git remote add [name] [url]
-
修改关联仓库
$git remote set-url --push[name][newUrl]
-
删除关联仓库
$git remote rm [name]
-
克隆远程仓库
$git clone https://github.com/youran1024/GitTest.git
$git clone git@github.com:youran1024/GitTest.git
-
创建本地仓库
$git init
-
关联远程仓库 (创建好本地的仓库后,通过此命令跟远程仓库做关联)
$git remote add origin git@server-name:path/#remoteRepository#.git
-
查看远程相关信息
$git remote -v
-
查看本地分支对应的远程分支
$git branch -vv
-
产看系统配置的文件
$git config --list
-
提交修改
$git push #remote# #branch#
-
获取服务器上的最新版本,并自动合并
$git pull #remote# #branch#
-
获取服务器上的最新版本,不做合并
$git fetch
-
删除文件
$git rm #file#
-
查看分支
$git branch
-
查看远程分支
$git branch -a
-
创建本地分支
$git branch #newBranch#
-
建立本地分支和远程分支的关联
$git branch --set-upstream #localBranch# origin/#remoteBranch#
本地的分支跟踪线上的分支
$git branch --track #newBranch# #remoteBranch#
-
创建远程分支到本地
$ git checkout -b #localBranch# origin/#remoteBranch#
-
创建分支 (把本地分支推送到远程,或者把本地的代码更新到远程对应的分支)
$git push origin #localBranchName#
-
切换分支
$git checkout #branchName#
-
创建并切换分支
$git checkout -b #branchName#
-
删除分支
$git branch -d #branchName#
-
强制删除分支(如果有没有提交的代码,需要强制删除,才能删掉分支,否则要首先撤掉修改过的代码)
$git branch -D #branchName#
-
删除远程分支
$git push origin --delete #remoteBranchName#
-
合并其它分支到当前分支
$git merge #branchName#
git rebase #branchName# 是把branch里的每一次提交生成一个补丁,然后跟当前的分支做合并。
$git rebase #branchName#
git rebase 的过程中会有冲突,冲突解决过后要用
$git rebase --continue
-
同步本地远程分支
$git checkout --track origin/develop
-
删除文件
$git rm #file#
-
添加文件
$git add .
`$git merge`
git rebase #branchName# 是把branch里的每一次提交生成一个补丁,然后跟当前的分支做合并。
`$git rebase`
-
和当前库里最新的作比较
$git diff HEAD -- #fileName#
-
没
$git add .
之前$git checkout -- #file#
单独撤销某个文件的修改
$git checkout HEAD #file#
-
撤销Commit 之前的操作 (版本指针做了重新的指向) 如果是--hard 撤销的话,则存储区内没有变化 如果是--soft(默认),则存储区将commit id 之前所有的commit发生的变化,放到了存储区。
$git reset HEAD #commit id#
先用Git Log 查看CommitID,根据Id做版本回退
-
撤销某个版本,但不影响其它的版本
$git revert #commitid#
-
回到当前版本(HEAD)的上一版本
--hard 撤销版本,不保留修改
$git reset --hard HEAD^
上上版本
$git reset --hard HEAD^^
上N个版本
$git reset --hard HEAD^~N
撤销版本,并保留修改
$git reset #commit id#
-
根据Commit ID 做回退
$git reset --hard #Commit id#
-
回退到某个版本,并保留当前的修改
$git reset --keep #commit id#
-
(往后回退了,又想往前回退)需要以前的Commit 记录
$git reflog
-
保存
$git stash
-
列表
$git stash list
-
恢复
$git stash apply
-
删除
$git stash drop
-
恢复并删除
$git stash pop
-
查看标签
$git tag
-
创建标签:
$git tag #tagName#
-
创建标签并添加标签信息
$git tag -a #tagname# -m "blablabla...
-
查看标签的信息
$git show #tagName#
-
提交Tag到远程 (提交操作同分支)
$git push origin #tagName#
-
提交本地所有的Tag (提交本地所有的分支那??)
$git push origin --tags
-
删除标签
$git tag -d #tagName#
-
删除远程tag
$git push origin :refs/tags/#tagname#
#####其它
-
那个文件都发生过哪些变化
$git log -p #file#
-
看看那个文件被谁改变过
$git blame #file#
-
酷炫的Git log 查看方式 个性化你的Log
[1]
git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset' --abbrev-commit --date=relative
[2]
git log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)#%an#%Creset' --abbrev-commit"
-
git 配置别名 (以后可以用 git lg 代替 git log --graph)
[git lg]显示图形化的Log
$git config --global alias.lg "log --graph"
[git last]查看看最后一次提交信息
$git config --global alias.last 'log -1'
-
忽略某些文件
GitHub已经为我们准备了各种配置文件gitHub
个性化你的Log
- 传送门:biu ~
关于git的详细介绍请参照#RED#廖雪峰#/RED#老师的讲解。
-
你要知道,工作区,暂存区,和版本库 工作区修改文件后,通过
git add .
添加到暂存区,如果没有问题,则通过git commit -m "#message#"
提交到版本库 -
在操作员称仓库前请注意你是否具有某远程仓库的操作权限
-
在熟练使用前请不要在线上分支上做练习
有失误之处欢迎修改
如果你需要补充这个文档,欢迎ForkMe并提交你的修改
- 传送门:Mr.Yang@github
2015 Copy right @Mr.Yang v1.0.0