# cd 项目目录下 git init #将整个项目文件加入暂存区 [liming@local project_name]$ git add . [liming@local project_name]$ git status # 位于分支 master # # 初始提交 # # 要提交的变动: # (使用 "git rm --cached <file>..." 撤出暂存区) liming@local project_name]$ git commit -m 'init add new files' [master(根提交) 450b4b4] init add new files ...... # 下面命令会增长URL地址为'git@github.com:liming/project_name.git',名称为origin的远程服务器库. # 之后提交代码的时候只须要使用 origin别名便可 liming@local project_name]$ git remote add origin git@github.com:liming/project_name.git # 显示远程仓库在本地名字 [liming@local project_name]$ git remote show origin # git push [remote-name] [branch-name] git push -u origin master
#符合以下规则的,未被track的文件,git将忽略 .DS_Store .gitignore *.swp application/.DS_Store
有时候在项目开发过程当中,忽然心血来潮想把某些目录或文件加入忽略规则,按照上述方法定义后发现并未生效,缘由是 .gitignore只能忽略那些原来没有被track的文件,若是某些文件已经被归入了版本管理中,则修改.gitignore是无效的。那么解决方法就是,先把本地缓存删除(改变成未track状态),而后再提交。php
[liming@local project_name]$ git rm -r --cached . [liming@local project_name]$ git add . [liming@local project_name]$ git commit -m 'update .gitignore'
git标签分为两种类型:轻量标签和附注标签。
# 轻量标签是指向提交对象的引用,附注标签则是仓库中的一个独立对象(建议使用附注标签)。
# 建立轻量标签
$ git tag v0.1.2-lightgit# 建立附注标签
$ git tag -a v0.1.2 -m “0.1.2版本”github区别:
建立轻量标签不须要传递参数,直接指定标签名称便可。
建立附注标签时,参数a即annotated的缩写,指定标签类型,后附标签名。参数m指定标签说明,说明信息会保存在标签对象中。vim切换到标签
#与切换分支命令相同
$ git checkout [tagname]centos查看标签列表
# 查看本地 tag 列表
$ git tag -l
查看具体标签信息
$ git show v0.1.2缓存删除标签
误打或须要修改标签时,须要先将标签删除,再打新标签。
$ git tag -d v0.1.2 #参数d即delete的缩写,意为删除其后指定的标签。bash给指定的commit打标签
# 打标签没必要要在head之上,也可在以前的版本上打,这须要你知道某个提交对象的校验和(经过git log 获取)。
# 补打标签
$ git tag -a v0.1.1 9fbc3d0服务器分享标签
# 默认状况下,git push 并不会把标签传送到远端服务器上,只有经过显式命令才能分享标签到远端仓库。其命令格式如同推送分支,运行 git push origin [tagname] 便可。
$ git push origin v0.1.2 #将v0.1.2标签提交到git服务器
$ git push origin –tags #一次推送全部本地新增的标签上去
$ git push origin --delete v0.1.2 #删除远程标签app注意:若是想看以前某个标签状态下的文件,能够这样操做spa
$ git tag #查看当前分支下的标签
$ git checkout v0.21 #此时会指向打v0.21标签时的代码状态,(但如今处于一个空的分支上)
$ cat test.txt #查看某个文件批量操做
# 批量删除远端标签
$ git show-ref --tag | awk '/(.*)(\s+)(.*)$/ {print ":" $2}' | xargs git push origin
# 批量删除本地标签(标签名为 1.0.0.* 的全部标签)
$ git tag | grep "1.0.0." | xargs git tag -d
流程:git checkout branch => git tag -a 版本号 -m 注释 => git push origin 版本号
# 比较两个分支的差别,将会以文件列表的形式展现(远程分支须要加 origin )
git diff branch1 origin/branch2 --stat
# 比较两个分支中文件的不一样
git diff branch1 origin/branch2 /path/具体文件
# 显示最近一次 stash 中的文件列表
git stash show
# 显示暂存区有多少条暂存记录,stash@{0},stash@{1}... 一条暂存记录会有多个文件
git stash list
# 暂存信息标识
git stash save 'message'
# 使用 stash@{1} 这个暂存
git stash apply stash@{1}
# 去掉 stash@{1} 这个 暂存
git stash drop stash@{1}
# 回退到某个版本
1)git log # 获取要回退的版本标识
2) git reset --hard 1)步骤历史版本的id
1. git config -l # 显示当前的 git config 的全部配置内容,内容所在文件:~/.gitconfig 和 .git/config
2. git 结合 vim 实现 commit 前的 diff 展现。
执行以下命令:
#git 实现vimdiff $ git config --global diff.tool vimdiff $ git config --global difftool.prompt false # 以下为 config git 操做命令 别名 配置 $ git config --global alias.d difftool
或者编辑你的 ~/.gitconfig 文件,添加如下各行:
[diff] tool = vimdiff [difftool] prompt = false [alias] d = difftool
如上配置完成后,就能够在 git commit 前,使用 git d 打开vim界面对比代码,而后用 :wq or :qa 继续比较下一个文件。
https://git-scm.com/docs (英文)
https://git-scm.com/book/zh/v2 (中文)
** mac开发,无文件大小写区分致使 centos 大小写同时存在,处理方法:
####### 出现 两个大小写文件 #### 还没有暂存以备提交的变动: # (使用 "git add <file>..." 更新要提交的内容) # (使用 "git checkout -- <file>..." 丢弃工做区的改动) # # 修改: application/controllers/Foo.php # 修改: application/controllers/foo.php # 修改还没有加入提交(使用 "git add" 和/或 "git commit -a") [liming@local project]$ git commit -m 'w' application/controllers/ [master 6f85312] w 2 file changed, 2 insertion(+) [liming@local project]$ git rm application/controllers/foo.php rm 'application/controllers/foo.php' [liming@local project]$ git status # 位于分支 master # 您的分支领先 'origin/master' 共 1 个提交。 # (使用 "git push" 来发布您的本地提交) # # 要提交的变动: # (使用 "git reset HEAD <file>..." 撤出暂存区) # # 删除: application/controllers/foo.php # # 还没有暂存以备提交的变动: # (使用 "git add/rm <file>..." 更新要提交的内容) # (使用 "git checkout -- <file>..." 丢弃工做区的改动) # # 删除: application/controllers/Foo.php # [liming@local project]$ git commit -m 'del foo.php' application/controllers/foo.php [master afabba6] del foo.php 1 file changed, 57 deletions(-) delete mode 100644 application/controllers/foo.php [liming@local project]$ git status # 位于分支 master # 您的分支领先 'origin/master' 共 1 个提交。 # (使用 "git push" 来发布您的本地提交) # # 还没有暂存以备提交的变动: # (使用 "git add/rm <file>..." 更新要提交的内容) # (使用 "git checkout -- <file>..." 丢弃工做区的改动) # # 删除: application/controllers/Foo.php # [liming@local project]$ git push # # 后续 git checkout application/controllers/Foo.php 这样就删除了git 库中的 foo.php
2.单服实践:
分支:
beta:标识文件env,设置 env = beta, 只合并 dev
① env=beta , git stash save "env=beta"
② env=online
dev: 标识文件env,设置 env = dev,合并到 beta 前 ,
① 只有 env=dev 的单文件, git stash save "env=dev";
② 存在 修改标识文件env的,设置 env = beta ,不存在 修改标识文件 env 的,直接 git commit -m 'mod' .
③ git checkout beta
④ git merge -m 'merge' dev
release:git merge -m