用户工具

站点工具


git

差别

这里会显示出您选择的修订版和当前版本之间的差别。

到此差别页面的链接

两侧同时换到之前的修订记录前一修订版
后一修订版
前一修订版
git [2016/09/20 09:20] – Add fix trick memorygit [2023/12/03 10:24] (当前版本) – 外部编辑 127.0.0.1
行 4: 行 4:
  
 ===== Common command ===== ===== 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 ===== ===== 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 ===== ===== Trick =====
 +
  
 [[https://robots.thoughtbot.com/how-to-fix-rm-f-git-index|How to fix `rm -f .git/index`]] [[https://robots.thoughtbot.com/how-to-fix-rm-f-git-index|How to fix `rm -f .git/index`]]
行 14: 行 99:
  
   git read-tree --reset HEAD   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.1474334435.txt.gz · 最后更改: 2023/12/03 10:24 (外部编辑)