text: (window.webpackJsonp=window.webpackJsonp||[]).push([[68],{452:function(t,a,r){"use strict";r.r(a);var s=r(27),e=Object(s.a)({},(function(){var t=this,a=t.$createElement,r=t._self._c||a;return r("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[r("h1",{attrs:{id:"git基本使用"}},[r("a",{staticClass:"header-anchor",attrs:{href:"#git基本使用"}},[t._v("#")]),t._v(" Git基本使用")]),t._v(" "),r("h2",{attrs:{id:"本地仓库关联到远程仓库"}},[r("a",{staticClass:"header-anchor",attrs:{href:"#本地仓库关联到远程仓库"}},[t._v("#")]),t._v(" 本地仓库关联到远程仓库")]),t._v(" "),r("ol",[r("li",[t._v("将本地项目初始化为git仓库\n"),r("ol",[r("li",[r("code",[t._v("git init")])])])]),t._v(" "),r("li",[t._v("远程新建repository")]),t._v(" "),r("li",[t._v("正式进行关联和推送\n"),r("ol",[r("li",[t._v("关联远程库： "),r("code",[t._v("git remote add origin git@server-name:path/repo-name.git")])]),t._v(" "),r("li",[t._v("推送本地仓库内容 ："),r("code",[t._v("git push -u origin master")]),t._v(" "),r("br")])])])]),t._v(" "),r("h2",{attrs:{id:"基本使用"}},[r("a",{staticClass:"header-anchor",attrs:{href:"#基本使用"}},[t._v("#")]),t._v(" 基本使用")]),t._v(" "),r("ol",[r("li",[t._v("工作目录---\x3e暂存区 ："),r("code",[t._v("git add .")])]),t._v(" "),r("li",[t._v("暂存区  ---\x3e本地仓库 ： "),r("code",[t._v('git commit -m "some commit info"')])]),t._v(" "),r("li",[t._v("本地仓库---\x3e远程仓库 ： "),r("code",[t._v("git push origin 分支名")])])]),t._v(" "),r("p",[r("strong",[t._v("注意事项：")])]),t._v(" "),r("ol",[r("li",[t._v("push到远程前要先pull远程数据")]),t._v(" "),r("li",[t._v("若有冲突需先解决冲突")]),t._v(" "),r("li",[t._v("然后再次提交(add和commit)")]),t._v(" "),r("li",[t._v("最后push(如果push到master分支，可以简写为"),r("code",[t._v("git push")]),t._v(")"),r("br"),t._v(" "),r("br")])]),t._v(" "),r("h2",{attrs:{id:"git-pull命令"}},[r("a",{staticClass:"header-anchor",attrs:{href:"#git-pull命令"}},[t._v("#")]),t._v(" git pull命令")]),t._v(" "),r("p",[r("strong",[t._v("作用")]),t._v("：取回远程仓库某个分支的更新，并与本地某个分支合并。"),r("br"),t._v(" "),r("strong",[t._v("完整语法")]),t._v("：git pull 远程主机名 远程分支名:本地分支名"),r("br"),t._v(" "),r("strong",[t._v("举例")]),t._v("："),r("code",[t._v("git pull origin wlk:main")]),t._v("       取回远程origin主机的wlk分支与本地的main分支合并。"),r("br"),t._v(" "),r("br")]),t._v(" "),r("h2",{attrs:{id:"暂存区回退到工作区"}},[r("a",{staticClass:"header-anchor",attrs:{href:"#暂存区回退到工作区"}},[t._v("#")]),t._v(" 暂存区回退到工作区")]),t._v(" "),r("p",[r("code",[t._v("git reset HEAD <file>")]),t._v(" 将file从暂存区回退到工作空间"),r("br"),t._v(" "),r("code",[t._v("git reset")]),t._v(" 简写，回滚暂存区的所有添加"),r("br"),t._v(" "),r("br")]),t._v(" "),r("h2",{attrs:{id:"取消本次修改"}},[r("a",{staticClass:"header-anchor",attrs:{href:"#取消本次修改"}},[t._v("#")]),t._v(" 取消本次修改")]),t._v(" "),r("p",[t._v("指还没有进入暂存区的修改。")]),t._v(" "),r("p",[r("code",[t._v("git checkout -- <file>")]),t._v(" 将工作空间的还没有add的修改取消掉\n"),r("br")]),t._v(" "),r("h2",{attrs:{id:"覆盖上次的commit"}},[r("a",{staticClass:"header-anchor",attrs:{href:"#覆盖上次的commit"}},[t._v("#")]),t._v(" 覆盖上次的commit")]),t._v(" "),r("p",[r("code",[t._v('git commit --amend -m "message"')]),t._v(" 覆盖掉上一次的commit信息\n"),r("br")]),t._v(" "),r("h2",{attrs:{id:"回退到指定版本"}},[r("a",{staticClass:"header-anchor",attrs:{href:"#回退到指定版本"}},[t._v("#")]),t._v(" 回退到指定版本")]),t._v(" "),r("p",[t._v("回退到上一个版本："),r("code",[t._v("git reset --hard HEAD^")]),r("br"),t._v("\n回退到上三个版本："),r("code",[t._v("git reset --hard HEAD^^^")]),r("br"),t._v("\n回退到指定版本："),r("code",[t._v("git reset --hard commit-id")]),r("br"),t._v(" "),r("strong",[t._v("注意")]),r("br"),t._v("\n1.版本回退时，若工作区和暂存区有未提交的修改，会被撤销掉。这点要"),r("strong",[t._v("特别注意")]),r("br"),t._v("\n2.若回退后，再想恢复，可用 "),r("code",[t._v("git reflog")]),t._v(" 查看历史命令，找到相关commit-id，再次reset。\n"),r("br")]),t._v(" "),r("h2",{attrs:{id:"分支操作"}},[r("a",{staticClass:"header-anchor",attrs:{href:"#分支操作"}},[t._v("#")]),t._v(" 分支操作")]),t._v(" "),r("ol",[r("li",[t._v("创建分支 ： "),r("code",[t._v("git branch 分支名")])]),t._v(" "),r("li",[t._v("切换分支  :  "),r("code",[t._v("git checkout 分支名")])]),t._v(" "),r("li",[t._v("创建并切换： "),r("code",[t._v("git checkout -b 分支名")])]),t._v(" "),r("li",[t._v("查看分支："),r("code",[t._v("git branch")])]),t._v(" "),r("li",[t._v("合并分支："),r("code",[t._v("git merge 分支名")]),t._v(" ---\x3e 合并其他分支到当前分支")]),t._v(" "),r("li",[t._v("删除分支 ： "),r("code",[t._v("git branch -d 分支名")])]),t._v(" "),r("li",[t._v("删除远程分支 ： "),r("code",[t._v("git push origin -d 分支名")])]),t._v(" "),r("li",[t._v("拉取远程分支(本地不存在的分支) : "),r("code",[t._v("git checkout -b 本地分支名 origin/远程分支名")])]),t._v(" "),r("li",[t._v("push本地存在而远程不存在的分支时，远程会自动创建分支")])]),t._v(" "),r("br"),t._v(" "),r("h2",{attrs:{id:"合并冲突"}},[r("a",{staticClass:"header-anchor",attrs:{href:"#合并冲突"}},[t._v("#")]),t._v(" 合并冲突")]),t._v(" "),r("div",{staticClass:"language-javascript extra-class"},[r("pre",{pre:!0,attrs:{class:"language-javascript"}},[r("code",[r("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<<")]),r("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<<")]),t._v("head    \n当前分支最新提交   \n"),r("span",{pre:!0,attrs:{class:"token operator"}},[t._v("===")]),r("span",{pre:!0,attrs:{class:"token operator"}},[t._v("===")]),r("span",{pre:!0,attrs:{class:"token operator"}},[t._v("===")]),r("span",{pre:!0,attrs:{class:"token operator"}},[t._v("===")]),t._v("   \n其他分支提交或当前分支其他人的提交   \n"),r("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">>>")]),r("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">>")]),t._v("其他commit"),r("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),t._v("id\n")])])]),r("ol",[r("li",[r("p",[t._v("当两个人同时更改了同一个文件的"),r("strong",[t._v("文件名")]),t._v("时，会冲突；手动合并文件，再提交。")])]),t._v(" "),r("li",[r("p",[t._v("远程删除了某文件，本地修改了该文件，导致本地修改的文件与不存在的文件冲突；解决办法是：1-删除该文件再提交；2-直接提交（需要再次add和commit）")])])]),t._v(" "),r("br"),t._v(" "),r("h2",{attrs:{id:"标签操作"}},[r("a",{staticClass:"header-anchor",attrs:{href:"#标签操作"}},[t._v("#")]),t._v(" 标签操作")]),t._v(" "),r("ol",[r("li",[t._v("切换到目标分支上")]),t._v(" "),r("li",[t._v("执行"),r("code",[t._v("git tag 标签名")]),r("br"),t._v(" "),r("strong",[t._v("在指定commit-id上打标签")]),t._v(" : "),r("code",[t._v("git tag 标签名 commit-id")]),r("br"),t._v(" "),r("strong",[t._v("打指定并标签信息")]),t._v(" ： "),r("code",[t._v('git tag -a 标签名 -m "message" commit-id')])])]),t._v(" "),r("p",[t._v("命令 "),r("code",[t._v("git push origin 标签名")]),t._v(" 可以推送一个本地标签；"),r("br"),t._v("\n命令 "),r("code",[t._v("git push origin --tags")]),t._v(" 可以推送全部未推送过的本地标签；"),r("br"),t._v("\n命令 "),r("code",[t._v("git tag -d 标签名")]),t._v(" 可以删除一个本地标签；"),r("br"),t._v("\n命令 "),r("code",[t._v("git push origin :refs/tags/标签名")]),t._v(" 可以删除一个远程标签。"),r("br"),t._v(" "),r("br")]),t._v(" "),r("h2",{attrs:{id:"强制获取远程最新版本"}},[r("a",{staticClass:"header-anchor",attrs:{href:"#强制获取远程最新版本"}},[t._v("#")]),t._v(" 强制获取远程最新版本")]),t._v(" "),r("div",{staticClass:"language-js extra-class"},[r("pre",{pre:!0,attrs:{class:"language-js"}},[r("code",[r("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("删除本地src"),r("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),r("span",{pre:!0,attrs:{class:"token operator"}},[t._v("--")]),r("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),r("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v("这一步可有可无，但是为保安全建议拷贝一下，以防万一\ngit fetch "),r("span",{pre:!0,attrs:{class:"token operator"}},[t._v("--")]),t._v("all\ngit reset "),r("span",{pre:!0,attrs:{class:"token operator"}},[t._v("--")]),t._v("hard origin"),r("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("分支名\ngit pull\n")])])]),r("br"),t._v(" "),r("h2",{attrs:{id:"强制推送本地代码"}},[r("a",{staticClass:"header-anchor",attrs:{href:"#强制推送本地代码"}},[t._v("#")]),t._v(" 强制推送本地代码")]),t._v(" "),r("div",{staticClass:"language-js extra-class"},[r("pre",{pre:!0,attrs:{class:"language-js"}},[r("code",[t._v("方法一：\ngit push "),r("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),t._v("f origin 分支名\n方法二：\n\t拷贝本地src\n\tpull代码\n    删除src\n    拷入src\n    push代码\n")])])]),r("br"),t._v(" "),r("h2",{attrs:{id:"git默认对文件名大小写不敏感"}},[r("a",{staticClass:"header-anchor",attrs:{href:"#git默认对文件名大小写不敏感"}},[t._v("#")]),t._v(" git默认对文件名大小写不敏感")]),t._v(" "),r("div",{staticClass:"language-python extra-class"},[r("pre",{pre:!0,attrs:{class:"language-python"}},[r("code",[t._v("git config "),r("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),r("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),t._v("get core"),r("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("ignorecase\n"),r("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# 查看是否文件名大小写敏感，true为不敏感，false为敏感")]),t._v("\n\ngit config core"),r("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("ignorecase false\n"),r("span",{pre:!0,attrs:{class:"token comment"}},[t._v("#将git设置为文件名大小写敏感")]),t._v("\n")])])])])}),[],!1,null,null,null);a.default=e.exports}}]);