Git使用备忘录

指令速查

雷区勿踩


常见错误和小技巧

git pull失败,提示:fatal: refusing to merge unrelated histories

1
2
3
git pull origin master --allow-unrelated-histories
#之后再
git push origin master

git add 添加文件夹而非全部修改文件

1
2
3
4
# 添加整个文件夹及内容
git add yourfile/
# 添加目录中所有此文件类型的文件
git add *.your_文件类型

与fork别人的仓库保持同步

  1. 将fork的项目添加到remote中
    1
    git remote add your_forked_project_name(whatever you like) https://your_forked_project_url.git
  2. 更新remote中所有远程repo
    1
    git fetch --all
  3. 进行同步
    1
    git rebase your_forked_project_name/master
  4. 将自己的远程仓库也同步
    1
    git push origin master

处理 github 不允许上传超过 100MB 文件的问题

移除错误缓存

1
2
3
4
# for file
git rm --cached path_of_a_giant_file
# for document
git rm --cached -r path_of_a_giant_file

重新提交后将大文件加入 Git Large File Stroage:

  1. 安装git-lfs: brew install git-lfs
  2. 在repository的根目录初始化:git lfs install
  3. 跟踪大文件名git lfs track "name_of_your_giant_file_not_your_path!"
  4. 正常提交推送:git add your_giant_file_path
  5. 搜索大文件:find ./ -size +100M

git commit后想要撤销到上一个commit

1
git reset --soft HEAD^

git push 提交代码时writing objects特别慢解决方案

1
git config --global http.postBuffer 524288000

引用参考资料和版权说明

  1. http://www.git-tower.com/blog/git-cheat-sheet-cn
  2. https://blog.csdn.net/wxs0124/article/details/50126953
  3. http://stackoverflow.com/questions/37937984/git-refusing-to-merge-unrelated-histories
  4. https://blog.csdn.net/xinqingwuji/article/details/79391453
  5. https://www.cnblogs.com/-walker/p/7278951.html
  6. https://blog.csdn.net/smart_graphics/article/details/78475735
  7. http://www.liuxiao.org/2017/02/git-%E5%A4%84%E7%90%86-github-%E4%B8%8D%E5%85%81%E8%AE%B8%E4%B8%8A%E4%BC%A0%E8%B6%85%E8%BF%87-100mb-%E6%96%87%E4%BB%B6%E7%9A%84%E9%97%AE%E9%A2%98/
  8. https://blog.csdn.net/w958796636/article/details/53611133
请zzy824喝杯咖啡
0%