|
|
| 第11行: |
第11行: |
| * [[/工具|工具]] | | * [[/工具|工具]] |
| * [[/Error|Error]] | | * [[/Error|Error]] |
|
| |
|
| |
| == 初始化 ==
| |
| {{shc|<syntaxhighlight lang="bash">
| |
| git init</syntaxhighlight>|$|/home/kangkk}}
| |
|
| |
| == 命令合并 ==
| |
| 命令可以进行合并。
| |
| {{hcdiff|head=|output=<syntaxhighlight lang="bash">
| |
| git add /src/a.js
| |
| git commit -m "edit the file"</syntaxhighlight>|output2=<syntaxhighlight lang="bash">
| |
| git commit -a -m "edit the file"
| |
| </syntaxhighlight>}}
| |
|
| |
| == commit ==
| |
| === rebase ===
| |
| === reset ===
| |
| 查看记录
| |
| {{shc|<syntaxhighlight lang="bash">
| |
| git log --oneline</syntaxhighlight>|$|/home/kangkk}}
| |
|
| |
| <div class="pageBoxGreen"><code>^</code> 表示前一次。<code>^^^^</code> 等价于 <code>~4</code>。<br>
| |
| {{hcdiff|head=|output=<syntaxhighlight lang="bash">
| |
| git reset fb69f9d^^^^</syntaxhighlight>|output2=<syntaxhighlight lang="bash">
| |
| git reset fb69f9d~4
| |
| </syntaxhighlight>}}</div>
| |
|
| |
| 取消最后一次 commit。
| |
| {{shc|<syntaxhighlight lang="bash">
| |
| git reset fb69f9d^
| |
| # or
| |
| git reset master^
| |
| # or
| |
| git reset HEAD^</syntaxhighlight>|$|/home/kangkk}}
| |
|
| |
| 回退到指定 commit
| |
| {{shc|<syntaxhighlight lang="bash">
| |
| git reset fb69f9d</syntaxhighlight>|$|/home/kangkk}}
| |
|
| |
| ==== --mixed ====
| |
| ==== soft ====
| |
| ==== hard ====
| |
|
| |
| === --amend ===
| |
| === 追加文件到 commit ===
| |
| ==== reset ====
| |
| 删除最后一次 commit,重新 commit。
| |
| ==== --amend --no-edit ====
| |
| 将文件并入最后一次 commit。使用 <code>--no-edit</code> 标识不进行编辑 commit 信息。
| |
| {{shc|<syntaxhighlight lang="bash">
| |
| git add src/a.js && \
| |
| git commit --amend --no-edit</syntaxhighlight>|$|/home/kangkk}}
| |
|
| |
| == 析出 ==
| |
| === 析出被删除文件 ===
| |
| 从暂存区析出文件。
| |
| {{shc|<syntaxhighlight lang="bash">
| |
| rm src/a.js && \
| |
| git checkout src/a.js</syntaxhighlight>|$|/home/kangkk}}
| |
|
| |
| 将文件致为上一次 commit 状态。
| |
| {{shc|<syntaxhighlight lang="bash">
| |
| git checkout HEAD~2 src/a.js</syntaxhighlight>|$|/home/kangkk}}
| |
|
| |
| == 其他 ==
| |
| === remote ===
| |
| 查看远程指引。
| |
| {{Shc_out|<syntaxhighlight lang="bash">
| |
| git remote
| |
| </syntaxhighlight>|<syntaxhighlight lang="bash">old-origin
| |
| origin
| |
| </syntaxhighlight>|$|/home/kangkk}}
| |
|
| |
| 删除远程
| |
| {{shc|<syntaxhighlight lang="bash">git remote rm old-origin</syntaxhighlight>|$|/home/kangkk}}
| |
|
| |
| 修改远程地址
| |
| {{shc|<syntaxhighlight lang="bash">
| |
| git remote set-url origin git@w.src.corp.qihoo.net:arena/arena-exp-serve.git</syntaxhighlight>|$|/home/kangkk}}
| |
|
| |
| 添加远程地址
| |
| {{Shc_out|<syntaxhighlight lang="bash">
| |
| git remote add origin git@w.src.corp.qihoo.net:arena/arena-exp-serve.git</syntaxhighlight>|<syntaxhighlight lang="bash">
| |
| </syntaxhighlight>|$|/home/kangkk}}
| |
|
| |
| {{Shc_out|<syntaxhighlight lang="bash">
| |
| git remote -v</syntaxhighlight>|<syntaxhighlight lang="bash">
| |
| origin git@v.src.corp.qihoo.net:qiwooiot/font.qiwoo.org.git (fetch)
| |
| origin git@v.src.corp.qihoo.net:qiwooiot/font.qiwoo.org.git (push)
| |
| </syntaxhighlight>|$|/home/kangkk}}
| |
|
| |
| === 常用命令 ===
| |
| {| class="wikitable"
| |
| |-
| |
| | 从master分支上切出一个test分支 || {{shc|<syntaxhighlight lang="bash">
| |
| git checkout master //切换到本地master分支
| |
| git pull origin master //更新远程master分支到本地
| |
| git checkout -b newBranch(本地) //创建并切换到newBranch分支
| |
| git push -u origin newBranch(远程) //推送到远程并与远程的newBranch关联</syntaxhighlight>|#}}
| |
| |-
| |
| | 合并本地分支 || {{shc|<syntaxhighlight lang="bash">
| |
| git checkout new_branch
| |
| git merge old_branch</syntaxhighlight>|#}} || old_branch 合并到 new_branch
| |
| |-
| |
| | 合并本地分支 || {{shc|<syntaxhighlight lang="bash">
| |
| git checkout new_branch
| |
| git rebase old_branch</syntaxhighlight>|#}} || old_branch 更新到 new_branch
| |
| |-
| |
| | 本地分支对比远程差异 || <code> git diff --stat kk origin/kk</code> || 示例
| |
| |-
| |
| | 示例 || <code> git log kk..origin/kk</code> || 示例
| |
| |-
| |
| | 拉去远程分支 || <code> git clone -b kk git@abc.com:user/project.git</code> || 示例
| |
| |-
| |
| | 本地分支回滚 || <code>git reset --hard commit-id</code> || 回滚到commit-id
| |
| |-
| |
| | || <code>git reset --hard HEAD~3</code> || 将最近3次的提交回滚
| |
| |-
| |
| | 远程分支回滚 || {{shc|<syntaxhighlight lang="bash">
| |
| git checkout the_branch
| |
| git pull
| |
| git branch the_branch_backup # 备份一下这个分支当前的情况
| |
| git reset --hard the_commit_id # the_branch 本地回滚到 the_commit_id
| |
| git push origin :the_branch # 删除远程 the_branch
| |
| git push origin the_branch # 用回滚后的本地分支重新建立远程分支
| |
| git push origin :the_branch_backup # 如果前面都成功了,删除这个备份分支</syntaxhighlight>|#}} || 回滚到commit-id
| |
| |-
| |
| | || {{shc|<syntaxhighlight lang="bash">
| |
| git reset --hard HEAD~1 # 本地代码回滚到上一版本(或者指定版本)
| |
| git push -f origin master # 加入-f参数,强制提交,远程端将强制跟新到reset版本</syntaxhighlight>|#}} || 将最近3次的提交回滚
| |
| |}
| |
|
| |
| == 切换分支 ==
| |
| <pre>
| |
| git clone https://github.com/kangkk/vue-webpack.git
| |
| cd vue-webpack/
| |
| git branch -a
| |
| git branch
| |
| git checkout ejs_vue
| |
| </pre>
| |
| == 定时拉取代码 ==
| |
| === crontab ===
| |
| {{shc|<syntaxhighlight lang="bash">
| |
| crontab -e</syntaxhighlight>|$}}
| |
| {{hc|/tmp/crontab.90pWnh|<syntaxhighlight lang="text">
| |
| */1 * * * * cd /root/vue-webpack/;/usr/local/bin/git pull origin ejs_vue
| |
| </syntaxhighlight>}}
| |
| 如果服务器端需要编译,可能会导致冲突
| |
| <syntaxhighlight lang="javascript">
| |
| 0 */1 * * * cd /root/vue-webpack/;/usr/bin/git fetch --all;/usr/bin/git reset --hard origin/ejs_vue;/usr/bin/git pull origin ejs_vue;/usr/local/bin/npm run dev</syntaxhighlight>
| |
|
| |
| === PHP ===
| |
| <syntaxhighlight lang="php">
| |
| exec("cd /root/vue-webpack/;/usr/local/bin/git pull origin ejs_vue");</syntaxhighlight>
| |
| === 密码 ===
| |
|
| |
| == 新建分支 ==
| |
| {| class="wikitable"
| |
| |-
| |
| | 切换到基础分支 || <syntaxhighlight lang="bash">
| |
| git checkout master</syntaxhighlight>
| |
| |-
| |
| | 创建并切换到新分支 || <syntaxhighlight lang="bash">
| |
| git checkout -b hbs</syntaxhighlight>
| |
| |-
| |
| | 更新分支代码并提交 || <syntaxhighlight lang="bash">
| |
| git add .
| |
| # git add *
| |
| git commit -m "init"
| |
| # git commit -a -m 'init'</syntaxhighlight>
| |
| |-
| |
| | 推送远端 || <syntaxhighlight lang="bash">
| |
| git push origin hbs</syntaxhighlight>
| |
| |}
| |
| === 分支创建分支 ===
| |
| {{shc|<syntaxhighlight lang="bash">
| |
| git checkout mergesearch
| |
| git checkout -b newpages
| |
| git push origin newpages
| |
| git pull
| |
| # git branch --set-upstream-to=origin/newpages</syntaxhighlight>|$}}
| |
|
| |
| == 合并 ==
| |
| === merge ===
| |
| {| class="wikitable"
| |
| |-
| |
| | 切换基础分支 || git checkout master
| |
| |-
| |
| | 合并 || git merge hbs
| |
| |-
| |
| | 分支合并分支 ||
| |
| |}
| |
| === rebase ===
| |
| == 撤销 ==
| |
| === 撤销 add ===
| |
| 查看 git 状态
| |
| {{Shc_out|<syntaxhighlight lang="bash">
| |
| git status</syntaxhighlight>|<syntaxhighlight lang="bash">On branch master
| |
|
| |
| No commits yet
| |
|
| |
| Untracked files:
| |
| (use "git add <file>..." to include in what will be committed)
| |
| .eslintrc
| |
| .gitignore
| |
| README.md
| |
| development.js
| |
| doc/
| |
| nginx.conf
| |
| package-lock.json
| |
| package.json
| |
| pm2.json
| |
| production.js
| |
| src/
| |
| test/
| |
| view/
| |
| www/
| |
|
| |
| nothing added to commit but untracked files present (use "git add" to track)
| |
| </syntaxhighlight>|$|/home/kangkk}}
| |
|
| |
| == 删除 ==
| |
| === 删除分支 ===
| |
| ==== 删除本地分支 ====
| |
| {| class="wikitable"
| |
| |-
| |
| | 切换基础分支 || git checkout master
| |
| |-
| |
| | 删除 || branch -d
| |
| |}
| |
| ==== 删除远程分支 ====
| |
| === 删除文件 ===
| |
| {{shc|<syntaxhighlight lang="bash">
| |
| git rm src/a.js</syntaxhighlight>|$|/home/kangkk}}
| |
|
| |
| ==== --cached ====
| |
| 让文件脱离 git 控制,但不真删除文件。
| |
| {{shc|<syntaxhighlight lang="bash">
| |
| git rm src/a.js --cached</syntaxhighlight>|$|/home/kangkk}}
| |
|
| |
| == 移动 ==
| |
| {{shc|<syntaxhighlight lang="bash">
| |
| git mv src/a.js src/b.js</syntaxhighlight>|$|/home/kangkk}}
| |
|
| |
| == 远程仓库 ==
| |
| === 临时分支 ===
| |
| {| class="wikitable"
| |
| |-
| |
| | git remote -v || 查询当前远程的版本 || <syntaxhighlight lang="javascript">
| |
| origin git@gitee.com:b***c/ask***-pc.git (fetch)
| |
| origin git@gitee.com:b***c/ask***-pc.git (push)</syntaxhighlight>
| |
| |-
| |
| | <!-- git pull origin master --> || 直接拉取并合并最新代码( 不推荐 ) || 示例
| |
| |-
| |
| | git fetch origin master:mastertmp || 获取最新代码到本地临时分支 || 示例
| |
| |-
| |
| | git diff mastertmp || 查看本地 mastertmp 分支与当前分支的版本差异 ||
| |
| |-
| |
| | git merge mastertmp || 合并最新临时分支到本地分支 ||
| |
| |-
| |
| | git branch -D mastertmp || 删除本地临时分支 ||
| |
| |}
| |
| === 没有临时分支 ===
| |
| {| class="wikitable"
| |
| |-
| |
| | git remote -v || 查询当前远程的版本 || <syntaxhighlight lang="javascript">
| |
| origin git@gitee.com:b***c/ask***-pc.git (fetch)
| |
| origin git@gitee.com:b***c/ask***-pc.git (push)</syntaxhighlight>
| |
| |-
| |
| | git fetch origin master || 获取远端的 origin/master 分支 || 示例
| |
| |-
| |
| | git log -p master..origin/master ||查看本地 master 与远端 origin/master 的版本差异 || 示例
| |
| |-
| |
| | git merge origin/master || 合并远端分支 origin/master 到当前分支 ||
| |
| |}
| |
|
| |
| == 重置本地分支 ==
| |
| {| class="wikitable"
| |
| |-
| |
| |拉去远程分支(可选)||<syntaxhighlight lang="bash">
| |
| git fetch --all</syntaxhighlight> || <syntaxhighlight lang="bash">
| |
| git fetch <远程主机名> <分支名></syntaxhighlight>
| |
| |-
| |
| | 丢弃本地变更重置为远端分支内容 || <syntaxhighlight lang="bash">
| |
| git reset --hard origin/branchName</syntaxhighlight>
| |
| |-
| |
| | || <syntaxhighlight lang="bash">
| |
| git pull</syntaxhighlight> || <syntaxhighlight lang="bash">
| |
| git pull <远程主机名> <远程分支名>:<本地分支名></syntaxhighlight>
| |
| |}
| |
|
| |
| == 拉取 ==
| |
| 从远程拉取分支到本地
| |
| {{shc|<syntaxhighlight lang="bash">
| |
| git checkout -b 本地分支名 origin/远程分支名</syntaxhighlight>|$}}
| |
|
| |
| 提交本地分支作为远程分支
| |
| {{shc|<syntaxhighlight lang="bash">
| |
| git push origin 本地分支名:远程分支名</syntaxhighlight>|$}}
| |
|
| |
| == 状态 ==
| |
| {{Shc_out|<syntaxhighlight lang="bash">
| |
| git status</syntaxhighlight>|<syntaxhighlight lang="bash">
| |
| 位于分支 master
| |
| 您的分支与上游分支 'origin/master' 一致。
| |
|
| |
| 无文件要提交,干净的工作区
| |
| </syntaxhighlight>|$|/home/kangkk}}
| |
|
| |
| == 提交 ==
| |
| === add ===
| |
| {| class="wikitable"
| |
| |-
| |
| ! 参数!! 描述 !! 示例
| |
| |-
| |
| | . || 当前目录全部,递归子目录 || git add .
| |
| |-
| |
| | --all || 当前项目全部,递归子目录 || git add --all
| |
| |-
| |
| | 文件相对地址 || 部分 || git add src/a.js
| |
| |}
| |
|
| |
| === commit ===
| |
|
| |
| == git pull ==
| |
| === 冲突 ===
| |
| 忽略本地修改,强制拉取远程到本地
| |
| <syntaxhighlight lang="javascript">
| |
| git fetch --all
| |
| git reset --hard origin/dev
| |
| git pull</syntaxhighlight>
| |
| == stash ==
| |
| <blockquote>
| |
| <syntaxhighlight lang="javascript">
| |
| git stash
| |
| </syntaxhighlight></blockquote>
| |
|
| |
| <code>git pull</code> 出现冲突后可以暂存本地修改 <code>git stash</code>,然后 <code>git pull</code> 更新代码,<code>git stash list</code> 可查看暂存记录列表,释放本地暂存 <code>git stash apply stash@{0}</code>。
| |
|
| |
| == diff ==
| |
| 任意两个版本的差异
| |
| {{shc|<syntaxhighlight lang="bash">
| |
| git diff master..test</syntaxhighlight>|$}}
| |
| master , test 的共有父分支和 test 分支之间的差异
| |
| {{shc|<syntaxhighlight lang="bash">
| |
| git diff master...test</syntaxhighlight>|$}}
| |
| 当前工作目录和上次提交与本地索引间的差异
| |
| {{shc|<syntaxhighlight lang="bash">
| |
| git diff</syntaxhighlight>|$}}
| |
| 查看在下次提交时要提交的内容,显示当前的索引和上次提交间的差异
| |
| {{shc|<syntaxhighlight lang="bash">
| |
| git diff --cached</syntaxhighlight>|$}}
| |
| 显示工作目录与上次提交时之间的所有差别
| |
| {{shc|<syntaxhighlight lang="bash">
| |
| git diff HEAD</syntaxhighlight>|$}}
| |
| == commit ==
| |
| {{Shc_out|<syntaxhighlight lang="bash">
| |
| git log --stat</syntaxhighlight>|<syntaxhighlight lang="bash">commit 1c791646bf9605c4380f94a84f3a89b8cc2fb60c (HEAD -> dev)
| |
| Merge: 823544a 2b2fa58
| |
| Author: kangjian <kangjian@360.cn>
| |
| Date: Tue Jul 13 11:41:29 2021 +0800
| |
|
| |
| 修改登录页大小
| |
|
| |
| commit 823544a7986d8e2913d443af0a58290b3fbc1f50
| |
| Author: kangjian <kangjian@360.cn>
| |
| Date: Tue Jul 13 11:36:16 2021 +0800
| |
|
| |
| 修改登录页大小
| |
|
| |
| ph-test/.gitignore | 6 +++---
| |
| ph-test/plugin/sign/net.qihoo.design/META-INF/signatures.xml | 10 +++++-----
| |
| ...ndex_page_script.66bceac724c9b0717f19.min.css => index_page_script.3898d67102797bd90e12.min.css} | 2 +-
| |
| .../css/{main_style.66bceac724c9b0717f19.min.css => main_style.3898d67102797bd90e12.min.css} | 0
| |
| ph-test/plugin/sign/net.qihoo.design/index.html | 2 +-
| |
| .../net.qihoo.design/js/{index_page_script.66bceac7.min.js => index_page_script.3898d671.min.js} | 0
| |
| .../js/{index_page_script.66bceac7.min.js.gz => index_page_script.3898d671.min.js.gz} | Bin
| |
| ph-test/plugin/sign/net.qihoo.design/manifest.json | 8 ++++----
| |
| ph-test/view/page/login/Frame.vue | 11 +++++++----
| |
| 9 files changed, 21 insertions(+), 18 deletions(-)
| |
| </syntaxhighlight>|$|/home/kangkk}}
| |
| === 参考 ===
| |
| * https://git-scm.com/book/zh/v2/Git-%E5%9F%BA%E7%A1%80-%E6%9F%A5%E7%9C%8B%E6%8F%90%E4%BA%A4%E5%8E%86%E5%8F%B2
| |
|
| |
| == 其他 ==
| |
| {| class="wikitable"
| |
| |-
| |
| | [[/清理仓库|清理仓库]]||[[/gitlab|gitlab]]
| |
| |-
| |
| | [[/ssh|ssh]]|| [[/environment_variable|environment variable]]
| |
| |}
| |
|
| |
| == 回滚 ==
| |
| {{Shc_out|<syntaxhighlight lang="bash">
| |
| git log
| |
| </syntaxhighlight>|<syntaxhighlight lang="bash">commit 71d6d4d66ad34d815372dde78a9afc64397ad3ee (HEAD -> test, origin/test)
| |
| Author: kangkk <365@kangkk.com>
| |
| Date: Tue Mar 9 10:41:05 2021 +0800
| |
|
| |
| 添加package-lock
| |
|
| |
| commit 90cf19e637d4852262e5925094f3c4cae40f10ef
| |
| Merge: 4930a02 edc565d
| |
| Author: kangkk <365@kangkk.com>
| |
| Date: Tue Mar 9 10:31:52 2021 +0800
| |
|
| |
| 修复冲突
| |
|
| |
| commit edc565d95099e428005a415524b6735405efba4e (origin/fix-coverIsNull, fix-coverIsNull)
| |
| Author: kangkk <365@kangkk.com>
| |
| Date: Tue Mar 9 10:28:43 2021 +0800
| |
|
| |
| 修复封面历史问题
| |
|
| |
| commit aba9aaa7c550eb78141c79b618096747be141ca0
| |
| Author: kangkk <365@kangkk.com>
| |
| Date: Tue Mar 9 10:13:55 2021 +0800
| |
|
| |
| 修复封面历史问题
| |
|
| |
| commit 988fb5dd4719e82c951b4cbfbe6b2d784290e1eb
| |
| Author: kangkk <365@kangkk.com>
| |
| Date: Mon Mar 8 18:57:22 2021 +0800
| |
| </syntaxhighlight>|$|/home/kangkk}}
| |
|
| |
| 然后回滚分支
| |
| {{shc|<syntaxhighlight lang="bash">git reset --hard 988fb5dd4719e82c951b4cbfbe6b2d784290e1eb
| |
| </syntaxhighlight>|$|/home/kangkk}}
| |
|
| |
| 查看修改状态
| |
|
| |
| {{shc|<syntaxhighlight lang="bash">git status
| |
| </syntaxhighlight>|$|/home/kangkk}}
| |
|
| |
| 远程仓库删除原有分支
| |
|
| |
| {{shc|<syntaxhighlight lang="bash">git push origin :test
| |
| git push origin test
| |
| </syntaxhighlight>|$|/home/kangkk}}
| |
|
| |
| == 分支之间差异 ==
| |
| === ^ ===
| |
| 查看 dev 有,而 master 中没有
| |
| {{shc|<syntaxhighlight lang="bash">
| |
| git log dev ^master</syntaxhighlight>|$}}
| |
|
| |
| 查看 dev 中比 master 中多提交了哪些内容
| |
| {{shc|<syntaxhighlight lang="bash">
| |
| git log master..dev</syntaxhighlight>|$}}
| |
|
| |
| 不知道谁提交的多谁提交的少,单纯想知道有什么不一样
| |
| {{shc|<syntaxhighlight lang="bash">
| |
| git log dev...master</syntaxhighlight>|$}}
| |
|
| |
| 显示出每个提交是在哪个分支上
| |
| {{shc|<syntaxhighlight lang="bash">
| |
| git log --left-right dev...master</syntaxhighlight>|$}}
| |
|
| |
| {{leftrightflex|
| |
| 注意 commit 后面的箭头,根据我们在 –left-right dev…master 的顺序,左箭头 < 表示是 dev 的,右箭头 > 表示是 master的}}
| |
| {{Unknown}}
| |
|
| |
| == 分支分叉 ==
| |
| 查看 commit 冲突
| |
| {{shc_out|<syntaxhighlight lang="bash">
| |
| git cherry origin/newsearch</syntaxhighlight>|<syntaxhighlight lang="text">
| |
| + 238d26d28bf26f3e6239f611eef0b4ba022ccc2b
| |
| + 4e73c503c36a32bd3898d0852d2345876c336110
| |
| + f3ca675e3099d5a78356a4b7956cd1f009256425
| |
| + 4679bcbf787aec6305774e43d7576668d6bb1fe1
| |
| + 7e66f0c6e3db96635fa7e8b605ed3dcd1e3ac246
| |
| + 8adc688966932c773d34f965bb6a67d3f4027031
| |
| + 8b7515bfab1f5f30982c9f91a4b4ee078bba584e
| |
| + 807eabc35f5b4c2b5bfcbe454336ec00e5f21a4c
| |
| + c0cbbc52bdb1f64d6e5f77009539d34ef9a95703
| |
| + 141a349c4a582c96a687dda5e753fe142d39530e
| |
| + 528b5078279a81ecb3689d90545f79a0967c7741
| |
| + 25d62a2e9150369dcf6e920155765b958b9667e3
| |
| + 75177225255744f17883db36499fd3d84e13d141
| |
| + c9e5296465d0d8c8d947d106b878172b0b8e46bc
| |
| + ae361a1cb6b9761c0d66d8b8012bc788bb79bb87
| |
| + 3cc4dbff74ff6aec5d860fa0c3b7bbb9c1a597eb
| |
| + c981f2493df605040687ba5eb72cb5d1bda081d5
| |
| + bebcd79093663b20311cd37f5a35be1bf187814a
| |
| + 9a0bffe2dc669c708a37cdfe88fe083d8ac9cc62
| |
| + 0edc40b2f6972a99615e15b03b6b06ef545f2618
| |
| + f210117a590d1bbe544c41633515c73585bee098
| |
| + d4e8ade08e51e99079a3d53459ac79e6a22971f0
| |
| + 5dd235085f3772ea9aa5ed8e7ebf1581070182fd
| |
| + b9dffb8828520ef77bc1ac316e6ab6842905711b
| |
| + 0670cf29a0110217aaea9c450d2d346f1c86801b
| |
| + a2ca7db00ef3f2d9600ac1e435261874c746945c
| |
| + 672f33756bf4ecb3c65fb9a1b972f1306677911c
| |
| </syntaxhighlight>|$}}
| |
| 回退到冲突的前一个 commit
| |
| {{shc|<syntaxhighlight lang="bash">
| |
| git reset --hard <commitID></syntaxhighlight>|$}}
| |
|
| |
| == cleanup ==
| |
| 所有被 <code>ignore</code>(忽略)的本地文件会被全部删除,而且是无法恢复的,因为远程仓库里根本就没有这些文件。
| |
| == gitee ==
| |
| 多账号
| |
| <syntaxhighlight lang="javascript">
| |
| git clone git@gitee.com:bjz***/askgo-admin-fe.git</syntaxhighlight>
| |
| == .gitignore ==
| |
| [[/gitignore|.gitignore]]
| |
| == 文件夹 ==
| |
| 今天遇到一个问题,在一个项目里,我添加了一个文件夹,然后 commit,后续考虑其他事情,又在移除了这个文件夹,commit,然后 push,结果造成在 gitlab 中,线上网站存在这个文件夹,而本地没有这个文件夹。
| |
|
| |
| 使用强删解决这个问题:
| |
| {{shc|<syntaxhighlight lang="bash">
| |
| git rm -r --cached photoshop-plugin-ts
| |
| git commit -m "删除photoshop插件"
| |
| git push -u origin kk_test
| |
| </syntaxhighlight>|#}}
| |
|
| |
| == 迁移 ==
| |
| 查看当前仓库地址。
| |
| {{shc|<syntaxhighlight lang="bash">
| |
| git remote -v</syntaxhighlight>|$|/home/kangkk}}
| |
| === git push --mirror ===
| |
|
| |
| === git remote set-url ===
| |
| 迁移单个分支。
| |
| {{Shc_out|<syntaxhighlight lang="bash">
| |
| git remote set-url origin ssh://git@192.168.31.5:10022/abc/xyz.git</syntaxhighlight>|<syntaxhighlight lang="bash">
| |
| </syntaxhighlight>|$|/home/kangkk}}
| |
| {{shc|<syntaxhighlight lang="bash">
| |
| git push</syntaxhighlight>|$|/home/kangkk}}
| |
|
| |
| 迁移所有分支。
| |
| {{Shc_out|<syntaxhighlight lang="bash">
| |
| cd existing_repo && \
| |
| git remote rename origin old-origin && \
| |
| git remote add origin ssh://git@192.168.31.5:10022/qihoo/medici-doc.git && \
| |
| git push -u origin --all && \
| |
| git push -u origin --tags</syntaxhighlight>|<syntaxhighlight lang="bash">
| |
| 枚举对象中: 81, 完成.
| |
| 对象计数中: 100% (81/81), 完成.
| |
| 使用 12 个线程进行压缩
| |
| 压缩对象中: 100% (59/59), 完成.
| |
| 写入对象中: 100% (81/81), 336.01 KiB | 84.00 MiB/s, 完成.
| |
| 总共 81(差异 15),复用 81(差异 15),包复用 0
| |
| To ssh://192.168.31.5:10022/abc/doc.git
| |
| * [new branch] master -> master
| |
| 分支 'master' 设置为跟踪来自 'origin' 的远程分支 'master'。
| |
| </syntaxhighlight>|$|/home/kangkk}}
| |
|
| |
| 检查仓库地址更改状态。
| |
| {{Shc_out|<syntaxhighlight lang="bash">
| |
| git remote show origin</syntaxhighlight>|<syntaxhighlight lang="bash">
| |
| * 远程 origin
| |
| 获取地址:ssh://git@192.168.31.5:10022/abc/xyz.git
| |
| 推送地址:ssh://git@192.168.31.5:10022/abc/xyz.git
| |
| HEAD 分支:main
| |
| 远程分支:
| |
| main 新的(下一次获取将存储于 remotes/origin)
| |
| refs/remotes/origin/master 过时(使用 'git remote prune' 来移除)
| |
| 为 'git pull' 配置的本地分支:
| |
| master 与远程 master 合并
| |
| </syntaxhighlight>|$|/home/kangkk}}
| |