用户工具

站点工具


git

这是本文档旧的修订版!


Git

Git是一个分布式版本控制系统,目前主要用于管理代码版本。

Common command

add

按节暂存(stage)/提交(commit)文件:

git add -p <filename>

tag

删除标签:

git tag -d <tag>

删除远程 origin 中的标签:

git push --delete origin <tag>

Useful command

clean

清理当前工作区为干净工作区:

git clean -d -x -f

bisect

Debug利器,通过二分法查找是哪个 commit 导致的bug

开始,设定在两个commit见二分查找(good为工作正常的commit,bad为工作错误的commit):

git bisect start
git bisect bad <commit-id>
git bisect good <commit-id>
# run and test

如果该commit工作仍然异常:

git bisect bad  # 将自动切换到下一个测试commit

直到工作正常为止:

git bisect good  # 将输出引入bug的commit

patch

生成 patch 文件:

git format-patch -1 <sha>
git format-patch -1 HEAD  # or

应用 patch 文件:

patch -p1 < ./change.patch

Trick

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

git update-index --assume-unchanged <filename>
 
# retrack
git update-index --no-assume-unchanged <filename>

管理多个ssh密钥

Linux是通过.ssh/config手动指定每个Host的ssh key来实现对多个ssh密钥的管理的,这个方法对于在需要github上切换使用多个帐号的人来说同样有效。

参考

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
git.1523020325.txt.gz · 最后更改: 2023/12/03 10:24 (外部编辑)