跳至内容
sdvcrx's wiki
用户工具
登录
站点工具
搜索
工具
显示页面
过去修订
Export to Markdown
反向链接
最近更改
媒体管理器
网站地图
登录
>
最近更改
媒体管理器
网站地图
您的足迹:
git
本页面只读。您可以查看源文件,但不能更改它。如果您觉得这是系统错误,请联系管理员。
====== Git ====== [[wp>Git_(software)|Git]]是一个分布式版本控制系统,目前主要用于管理代码版本。 ===== Common command ===== ==== add ==== 按节暂存(stage)/提交(commit)文件: <code bash> git add -p <filename> </code> ==== commit ==== 指定 commit 时间: <code bash> d='2017-01-02T15:33:44' GIT_AUTHOR_DATE="$d" GIT_COMMITTER_DATE="$d" git cm -m 'msg' # or GIT_AUTHOR_DATE="$d" git cm -m 'msg' --date "$d" </code> ==== tag ==== 删除标签: <code bash> git tag -d <tag> </code> 删除远程 origin 中的标签: <code bash> git push --delete origin <tag> </code> ===== Useful command ===== ==== clean ==== 清理当前工作区为干净工作区: <code bash> git clean -d -x -f </code> ==== bisect ==== Debug利器,通过二分法查找是哪个 ''commit'' 导致的bug 开始,设定在两个commit见二分查找(good为工作正常的commit,bad为工作错误的commit): <code bash> git bisect start git bisect bad <commit-id> git bisect good <commit-id> # run and test </code> 如果该commit工作仍然异常: <code bash> git bisect bad # 将自动切换到下一个测试commit </code> 直到工作正常为止: <code bash> git bisect good # 将输出引入bug的commit </code> ==== patch ==== 生成 ''patch'' 文件: <code bash> git format-patch -1 <sha> git format-patch -1 HEAD # or git format-patch <sha> # format patch from <sha> to HEAD </code> 应用 ''patch'' 文件: <code bash> git am ./change.patch </code> ===== Trick ===== [[https://robots.thoughtbot.com/how-to-fix-rm-f-git-index|How to fix `rm -f .git/index`]] If you try to delete ''.git/index.lock'' but accidentally delete ''.git/index'', you can recover this repo by using this commands(All unstaged changes will lose, sorry, blame yourself): git read-tree --reset HEAD ---- Ignore some tracked files <code bash> git update-index --assume-unchanged <filename> # retrack git update-index --no-assume-unchanged <filename> </code> ---- **Change commited username/email** <code bash> git filter-branch -f --env-filter \ "GIT_AUTHOR_NAME='NAME'; GIT_AUTHOR_EMAIL='EMAIL'; \ GIT_COMMITTER_NAME='NAME'; GIT_COMMITTER_EMAIL='EMAIL';" HEAD # need to push force git push --force </code> ==== 管理多个ssh密钥 ==== Linux是通过.ssh/config手动指定每个Host的ssh key来实现对多个ssh密钥的管理的,这个方法对于在需要github上切换使用多个帐号的人来说同样有效。 [[https://gist.github.com/jexchan/2351996#gistcomment-1332446|参考]] <code> Host my-user-name.github.com HostName github.com User git IdentityFile ~/.ssh/id_rsa IdentitiesOnly yes Host company.github.com HostName github.com User git IdentityFile ~/.ssh/id_rsa_company IdentitiesOnly yes </code>
git.txt
· 最后更改: 2023/12/03 10:24 由
127.0.0.1
页面工具
显示页面
过去修订
反向链接
Export to Markdown
回到顶部