查看“︁Git”︁的源代码
来自康健生活
←
Git
因为以下原因,您没有权限编辑该页面:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
{| |- | [[/起源|起源]] || || |- | || [[/关键字|关键字]] || |- | || [[/源|源]] || |- | || [[/仓库|仓库]] || |} == 草稿 == * 标签 -> [[/Tag|标签 tag]] == Git == == 测试连接 == {{Shc_out|<syntaxhighlight lang="bash"> ssh -T git@github.com</syntaxhighlight>|<syntaxhighlight lang="bash"> git@github.com: Permission denied (publickey). </syntaxhighlight>|$|/home/kangkk}} 如果是自搭建的 git 仓库,并且更改了 ssh 端口。 {{Shc_out|<syntaxhighlight lang="bash"> ssh -T git@192.168.31.5:10022</syntaxhighlight>|<syntaxhighlight lang="bash"> ssh: Could not resolve hostname 192.168.31.5:10022: nodename nor servname provided, or not known </syntaxhighlight>|$|/home/kangkk}} 这个时候就需要更改一下写法。 {{Shc_out|<syntaxhighlight lang="bash"> ssh -p 10022 git@192.168.31.5 </syntaxhighlight>|<syntaxhighlight lang="bash"> The authenticity of host '[192.168.31.5]:10022 ([192.168.31.5]:10022)' can't be established. ECDSA key fingerprint is SHA256:GXLtCkYhXQ8RlHcrAyQKeTvLlBFXfWN2eBQXiou5c6I. Are you sure you want to continue connecting (yes/no/[fingerprint])? yes Warning: Permanently added '[192.168.31.5]:10022' (ECDSA) to the list of known hosts. PTY allocation request failed on channel 0 Welcome to GitLab, @root! Connection to 192.168.31.5 closed. </syntaxhighlight>|$|/home/kangkk}} == 安装 == === window === === linux === === mac === 安装 Homebrew。 {{Shc_out|<syntaxhighlight lang="bash"> /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" </syntaxhighlight>|<syntaxhighlight lang="bash"> Warning: The Ruby Homebrew installer is now deprecated and has been rewritten in Bash. Please migrate to the following command: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" ==> Checking for `sudo` access (which may request your password)... Password: ==> This script will install: /usr/local/bin/brew /usr/local/share/doc/homebrew /usr/local/share/man/man1/brew.1 /usr/local/share/zsh/site-functions/_brew /usr/local/etc/bash_completion.d/brew /usr/local/Homebrew ==> The following existing directories will be made writable by user only: /usr/local/share/zsh /usr/local/share/zsh/site-functions Press RETURN/ENTER to continue or any other key to abort: ==> /usr/bin/sudo /bin/chmod u+rwx /usr/local/share/zsh /usr/local/share/zsh/site-functions ==> /usr/bin/sudo /bin/chmod go-w /usr/local/share/zsh /usr/local/share/zsh/site-functions ==> /usr/bin/sudo /usr/sbin/chown -R kangjian:admin /usr/local/Homebrew ==> Downloading and installing Homebrew... remote: Enumerating objects: 331, done. remote: Counting objects: 100% (264/264), done. remote: Compressing objects: 100% (72/72), done. remote: Total 331 (delta 203), reused 228 (delta 187), pack-reused 67 接收对象中: 100% (331/331), 146.58 KiB | 374.00 KiB/s, 完成. 处理 delta 中: 100% (213/213), 完成 64 个本地对象. 来自 https://github.com/Homebrew/brew 663c0a713..c65bb5d12 master -> origin/master * [新标签] 3.4.5 -> 3.4.5 HEAD 现在位于 c65bb5d12 Merge pull request #13094 from Homebrew/org-discussions Updated 4 taps (homebrew/core, homebrew/cask, homebrew/services and mongodb/brew). ==> Installation successful! ==> Homebrew has enabled anonymous aggregate formulae and cask analytics. Read the analytics documentation (and how to opt-out) here: https://docs.brew.sh/Analytics No analytics data has been sent yet (nor will any be during this install run). ==> Homebrew is run entirely by unpaid volunteers. Please consider donating: https://github.com/Homebrew/brew#donations ==> Next steps: - Run brew help to get started - Further documentation: https://docs.brew.sh </syntaxhighlight>|➜ ~}} 安装 git。 {{shc|<syntaxhighlight lang="bash"> brew install git</syntaxhighlight>|➜ ~}} == 暂存区 == == 用户设置 == {{Shc_out|<syntaxhighlight lang="bash"> git config --list</syntaxhighlight>|<syntaxhighlight lang="bash"> credential.helper=osxkeychain user.name=kangjian user.email=kangjian@360.cn </syntaxhighlight>|➜ ~}} === --global === 设置全局用户信息。 {{shc|<syntaxhighlight lang="bash"> git config --global user.name "kangkk" && \ git config --global user.email "365@kangkk.com"</syntaxhighlight>|$|/home/kangkk}} === --local === 单独设置项目内用户信息。 {{shc|<syntaxhighlight lang="bash"> git config --local user.name "kangjian" && \ git config --local user.email "kangjian@360.cn"</syntaxhighlight>|$|/home/kangkk}} === 设置编辑器 === {{shc|<syntaxhighlight lang="bash"> git config --global core.editor emacs</syntaxhighlight>|$|/home/kangkk}} === 设置缩写 === {{shc|<syntaxhighlight lang="bash"> git config --global alias.co checkout git config --global alias.l "log --graph --oneline " git config --global alias.ls 'log --graph --pretty=format:"%h <%an> %ar %s"'</syntaxhighlight>|$|/home/kangkk}} 示例,查看 log 信息。 {{Shc_out|<syntaxhighlight lang="bash"> git l</syntaxhighlight>|<syntaxhighlight lang="bash"> * 7376210 (HEAD -> master, origin/master, origin/HEAD) 添加通过数据库查询最后版本号码的说明 * 2afdd49 添加通过数据库查询最后版本号码 ... * b7b05de 更新 https 证书 * f199050 Merge branch 'master' of git.a.b.net:qiwoo/xxx |\ | * 44ad8c1 fix bug | * 82685ae fix typo | * 1dc08a2 fix typo | * b5f5d7a 增加 ${HOSTNAME} 注入 | * 57e0681 更新日志位置 | * ae6b865 update think-logger 版本 * | 9ab1663 更新https的ssl证书 |/ * 6a54234 remove @2017 </syntaxhighlight>|$|/home/kangkk}} {{Shc_out|<syntaxhighlight lang="bash"> git ls </syntaxhighlight>|<syntaxhighlight lang="bash"> * 7376210 <kangjian> 6 周前 添加通过数据库查询最后版本号码的说明 ... * b7b05de <lizheming> 2 年 1 个月前 更新 https 证书 * f199050 <linxd> 2 年 2 个月前 Merge branch 'master' of git.a.b.net:qiwoo/xxx |\ | * 44ad8c1 <lizheming> 2 年 3 个月前 fix bug | * 82685ae <lizheming> 2 年 3 个月前 fix typo | * 1dc08a2 <lizheming> 2 年 3 个月前 fix typo | * b5f5d7a <lizheming> 2 年 3 个月前 增加 ${HOSTNAME} 注入 | * 57e0681 <lizheming> 2 年 3 个月前 更新日志位置 | * ae6b865 <lizheming> 2 年 6 个月前 update think-logger 版本 * | 9ab1663 <linxd> 2 年 2 个月前 更新https的ssl证书 |/ * 6a54234 <linxd> 2 年 6 个月前 remove @2017 </syntaxhighlight>|$|/home/kangkk}} == 配置文件 == === .gitconfig === {{Hc|.gitconfig|<syntaxhighlight lang="text"> [user] name = kangjian email = kangjian@360.cn [alias] l = log --oneline --graph</syntaxhighlight>}} === .gitignore === == 初始化 == {{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>}} == log == === 查找人 === 查找单人。 {{shc|<syntaxhighlight lang="bash"> git log --online --author="kangjian"</syntaxhighlight>|$|/home/kangkk}} 查找多人。 {{shc|<syntaxhighlight lang="bash"> git log --online --author="kangjian\|lanqian"</syntaxhighlight>|$|/home/kangkk}} === 查找关键字 === {{shc|<syntaxhighlight lang="bash"> git log --online --grep="kangkk"</syntaxhighlight>|$|/home/kangkk}} === 查找文件内容信息 === {{shc|<syntaxhighlight lang="bash"> git log -S "75cdn"</syntaxhighlight>|$|/home/kangkk}} === 查找时间区间 === 查找自2021年2月24日以后,早上10点到下午8点的记录。 {{shc|<syntaxhighlight lang="bash"> git log --online --since="10am" --until="8pm" --after="2021-02-24"</syntaxhighlight>|$|/home/kangkk}} === 查看文件 === {{shc|<syntaxhighlight lang="bash"> git log src/a.js</syntaxhighlight>|$|/home/kangkk}} 查看文件改动记录。 {{shc|<syntaxhighlight lang="bash"> git log -p src/a.js</syntaxhighlight>|$|/home/kangkk}} == reflog == {{shc|<syntaxhighlight lang="bash"> git reflog</syntaxhighlight>|$|/home/kangkk}} == 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}} == 工具 == === git_stats === === cloc === {{shc|<syntaxhighlight lang="bash"> brew install cloc </syntaxhighlight>|jian:kang kangjian$}} 使用。 {{Shc_out|<syntaxhighlight lang="bash"> cloc ./</syntaxhighlight>|<syntaxhighlight lang="bash"> 378 text files. 345 unique files. 50 files ignored. github.com/AlDanial/cloc v 1.92 T=0.62 s (555.8 files/s, 110143.4 lines/s) ------------------------------------------------------------------------------- Language files blank comment code ------------------------------------------------------------------------------- JSON 11 2 0 37638 JavaScript 190 1697 2924 16433 CSS 31 247 106 3148 LESS 42 164 139 2875 SVG 31 7 9 1059 TypeScript 24 121 186 850 Markdown 7 72 0 243 YAML 1 22 31 160 HTML 2 2 11 124 XML 1 0 0 42 Dockerfile 5 13 0 39 ------------------------------------------------------------------------------- SUM: 345 2347 3406 62611 ------------------------------------------------------------------------------- </syntaxhighlight>|$|/home/kangkk}} == 统计 == === 个人代码提交量 === {{Shc_out|<syntaxhighlight lang="bash"> git log --author="kangjian" --pretty=tformat: --numstat | awk '{ add += $1; subs += $2; loc += $1 - $2 } END { printf "added lines: %s, removed lines: %s, total lines: %s\n", add, subs, loc }' - </syntaxhighlight>|<syntaxhighlight lang="bash"> added lines: 170168, removed lines: 51562, total lines: 118606 </syntaxhighlight>|$|/home/kangkk}} 个人代码提交,附带时间区间。 {{Shc_out|<syntaxhighlight lang="bash"> git log --author=kangjian --since=2021-02-01 --until=2022-02-01 --format='%aN' | sort -u | while read name; do echo -en "$name\t"; git log --author="$name" --pretty=tformat: --numstat | grep "\(.html\|.java\|.xml\|.properties\)$" | awk '{ add += $1; subs += $2; loc += $1 - $2 } END { printf "added lines: %s, removed lines: %s, total lines: %s\n", add, subs, loc }' -; done</syntaxhighlight>|<syntaxhighlight lang="bash"> kangjian added lines: 94, removed lines: 16, total lines: 78 </syntaxhighlight>|$|/home/kangkk}} === 增删代码量 === {{Shc_out|<syntaxhighlight lang="bash"> git log --format='%aN' | sort -u | while read name; do echo -en "$name\t"; git log --author="$name" --pretty=tformat: --numstat | awk '{ add += $1; subs += $2; loc += $1 - $2 } END { printf "added lines: %s, removed lines: %s, total lines: %s\n", add, subs, loc }' -; done</syntaxhighlight>|<syntaxhighlight lang="bash"> cuili added lines: 19476, removed lines: 105928, total lines: -86452 heweixiao added lines: 3371, removed lines: 1532, total lines: 1839 kangjian added lines: 4571, removed lines: 1215950, total lines: -1211379 liuguanyu added lines: 1777938, removed lines: 106, total lines: 1777832 xuke5 added lines: 42708, removed lines: 590, total lines: 42118 </syntaxhighlight>|$|/home/kangkk}} === 总代码行数 === {{Shc_out|<syntaxhighlight lang="bash"> git log --format='%aN' | sort -u | while read name; do echo -en "$name\t"; git log --author="$name" --pretty=tformat: --numstat | grep "\(.html\|.java\|.xml\|.properties\|.css\|.js\|.txt\)$" | awk '{ add += $1; subs += $2; loc += $1 - $2 } END { printf "added lines: %s, removed lines: %s, total lines: %s\n", add, subs, loc }' -; done</syntaxhighlight>|<syntaxhighlight lang="bash"> chenyiwen added lines: 32, removed lines: 19, total lines: 13 kangjian added lines: 9978, removed lines: 7263, total lines: 2715 kangkk added lines: 44189, removed lines: 37408, total lines: 6781 lizheming added lines: 14833, removed lines: 5913, total lines: 8920 shuliqi added lines: , removed lines: , total lines: wwenj added lines: 400, removed lines: 167, total lines: 233 yangyalin added lines: 286, removed lines: 138, total lines: 148 yangyalin1 added lines: 286, removed lines: 138, total lines: 148 yuyang7 added lines: 3926, removed lines: 1299, total lines: 2627 zhaowenbo added lines: 2396, removed lines: 432, total lines: 1964 康健 added lines: 8661, removed lines: 6907, total lines: 1754 </syntaxhighlight>|$|/home/kangkk}} === 贡献值统计 === {{Shc_out|<syntaxhighlight lang="bash"> git log --pretty='%aN' | sort -u | wc -l</syntaxhighlight>|<syntaxhighlight lang="bash"> 5 </syntaxhighlight>|$|/home/kangkk}} === 提交数统计 === {{Shc_out|<syntaxhighlight lang="bash"> git log --oneline | wc -l</syntaxhighlight>|<syntaxhighlight lang="bash"> 411 </syntaxhighlight>|$|/home/kangkk}} === 统计或修改的行数 === {{Shc_out|<syntaxhighlight lang="bash"> git log --stat|perl -ne 'END { print $c } $c += $1 if /(\d+) insertions/' </syntaxhighlight>|<syntaxhighlight lang="bash"> 1848029 </syntaxhighlight>|$|/home/kangkk}} == 提交次数排名 == {{Shc_out|<syntaxhighlight lang="bash"> git log --pretty='%aN' | sort | uniq -c | sort -k1 -n -r | head -n 5</syntaxhighlight>|<syntaxhighlight lang="bash"> 160 kangjian 93 cuili 61 liuguanyu 56 heweixiao 41 xuke5 </syntaxhighlight>|$|/home/kangkk}} === 统计或修改的行数 === {{Shc_out|<syntaxhighlight lang="bash"> git log --stat|perl -ne 'END { print $c } $c += $1 if /(\d+) insertions/'</syntaxhighlight>|<syntaxhighlight lang="bash"> 257528 </syntaxhighlight>|$|/home/kangkk}} == 其他 == === git-lfs === 使用 [https://github.com/git-lfs/git-lfs git-lfs] 管理大文件。 == error == * Automatic merge failed; fix conflicts and then commit the result. : {{shc_out|<syntaxhighlight lang="bash"> git status</syntaxhighlight>|<syntaxhighlight lang="text"> On branch newsearch Your branch is up to date with 'origin/newsearch'. You have unmerged paths. (fix conflicts and run "git commit") (use "git merge --abort" to abort the merge) Changes to be committed: new file: .babelrc modified: .eslintignore modified: api/consult.js modified: api/prepose.js new file: assets/img/search/collect-2.png ... Unmerged paths: (use "git add <file>..." to mark resolution) both modified: README.md both modified: api/conf.js both added: api/search.js ... </syntaxhighlight>|$}} :: 1. 丢弃本地分支内容,本地的内容将会被丢弃,慎用 ::{{shc|<syntaxhighlight lang="bash"> git reset --hard origin/mergesearch</syntaxhighlight>|$}} :: 或者 ::{{shc|<syntaxhighlight lang="bash"> git reset --hard ORIG_HEAD # 慎用</syntaxhighlight>|$}} :: 2. 合并以后的文件内容混乱,废弃此次合并,回到合并之前的状态 :: {{shc|<syntaxhighlight lang="bash"> git reset --hard HEAD</syntaxhighlight>|$}} * error: Merging is not possible because you have unmerged files. : {{shc|<syntaxhighlight lang="bash"> git diff git status</syntaxhighlight>|$}} * fatal: cannot do a partial commit during a merge. : git 认为有部分代码没有做好提交的准备 : {{shc_out|<syntaxhighlight lang="bash"> git commit -a</syntaxhighlight>|<syntaxhighlight lang="text"> GNU nano 2.9.3 /mnt/d/gitee/***-**-pc/.git/COMMIT_EDITMSG Merge branch 'newsearch' of gitee.com:bjzyxc/ask-go-pc into newsearch # Conflicts: # README.md # api/conf.js # api/search.js # components/common/header/index.vue # config/env.js # layouts/search.vue # pages/search.vue # pages/search/list.vue # pages/search/listLeftArticle.vue # pages/search/listLeftUser.vue # pages/search/listRight.vue # pages/search/navmenu.vue # plugins/bus.js # plugins/router.js # server/index.js # # It looks like you may be committing a merge. # If this is not correct, please remove the file # .git/MERGE_HEAD # and try again. [ Read 115 lines ] ^G Get Help ^O Write Out ^W Where Is ^K Cut Text ^J Justify ^C Cur Pos M-U Undo M-A Mark Text M-] To Bracket ^X Exit ^R Read File ^\ Replace ^U Uncut Text ^T To Spell ^_ Go To Line M-E Redo M-6 Copy Text M-W WhereIs Next</syntaxhighlight>|$}} * It looks like you may be committing a merge. # If this is not correct, please remove the file * <syntaxhighlight lang="javascript"> remote: Enumerating objects: 1, done. remote: Counting objects: 100% (1/1), done. remote: Total 1 (delta 0), reused 0 (delta 0) Unpacking objects: 100% (1/1), done. From w.src.corp.qihoo.net:design/dome e99cf03..86a552c master -> origin/master error: cannot lock ref 'refs/remotes/origin/test': Unable to create '/mnt/d/360/demo/.git/refs/remotes/origin/test.lock': File exists. Another git process seems to be running in this repository, e.g. an editor opened by 'git commit'. Please make sure all processes are terminated then try again. If it still fails, a git process may have crashed in this repository earlier: remove the file manually to continue. ! f15b60c..0bacea2 test -> origin/test (unable to update local ref)</syntaxhighlight> * <code>! [rejected] fixWebLabel -> fixWebLabel (non-fast-forward)</code> :: {{shc|<syntaxhighlight lang="bash"> git pull --rebase origin fixWebLabel git push -u origin fixWebLabel</syntaxhighlight>|$|/home/kangkk}} * error: pathspec 'yy-dev' did not match any file(s) known to git : 先检查分支 <code>git branch -a</code> * 未完成合并(MERGE_HEAD存在) :: {{shc|<syntaxhighlight lang="bash"> git merge --abort git reset --merge git pull</syntaxhighlight>|$|/home/kangkk}}
返回
Git
。
导航菜单
康健生活
搜索
user-page
通知
user-interface-preferences
个人工具
登录
五一
多读书,多运动,多到远处走走,再看看不一样的世界。