git - doubility-sky/daydayup Wiki

Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.

Git is easy to learn and has a tiny footprint with lightning fast performance. It outclasses SCM tools like Subversion, CVS, Perforce, and ClearCase with features like cheap local branching, convenient staging areas, and multiple workflows.

GUI Clients

Git comes with built-in GUI tools for committing (git-gui) and browsing (gitk), but there are several third-party tools for users looking for platform-specific experience.

  • :star:Fork for Windows and Mac
  • Sourcetree: A free Git client for Windows and Mac
  • GitKraken: Legendary Git client for Windows, Mac & Linux. Free for open source
  • lazygit: simple terminal UI for git commands

Learn

tutorial

commit style

git flow

Common Usage

delete & clean

  • 删除本地所有未提交的更改
    • git clean -df 只删除所有untracked的文件,可后接指定目录
    • git clean -xdf 删除untracked以及ignore的文件
    • git reset --hard 把tracked的文件revert到前一个版本
  • 永久删除某个文件,包括服务器端
    git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch FILENAME' --prune-empty --tag-name-filter cat -- --all
    git push origin master --force
    

gitignore

  • github/gitignore: A collection of useful .gitignore templates
  • 忽略特定结构目录
    • 忽略一个特定的文件:/filename.extension
    • 忽略所有同名的文件:filename.extension
    • 忽略一个特定的目录:folder/(这会连同其下所有子目录及文件都被忽略)
    • 但是排除一个特定的模式:(在 3 的基础上)!folder/some/important/filename.extension
    • 忽略指定目录下所有子目录下的特定文件:folder/**/filename.extension
    • 同上,但是只匹配文件扩展名:folder/**/*.extension
    • 同上,但是只匹配特定的目录:folder/**/tmp/

GitHub Guides

projects

  • github-rank: 🕷️Github 中国和全球用户排名,全球仓库 Star 最多排名(自动日更)。
  • GitHunt: Hunt the most starred projects on any date on GitHub
  • HelloGitHub: Find pearls on open-source seashore 分享 GitHub 上有趣、入门级的开源项目

profiles

Tools

  • git filter-repo is a versatile tool for rewriting history
  • Lepton is a lean code snippet manager based on GitHub Gist. Check out its latest release.
  • GRV is a terminal interface for viewing git repositories
  • git-crypt enables transparent encryption and decryption of files in a git repository.
  • Git Extensions is a standalone UI tool for managing git repositories. It also integrates with Windows Explorer and Microsoft Visual Studio
  • hexo: A fast, simple & powerful blog framework
  • dulwich: Pure-Python Git implementation

statistics

  • ▁▅▆▃▅ Git quick statistics is a simple and efficient way to access various statistics in git repository.
  • git-fame is a command-line tool that helps you summarize and pretty-print collaborators in a git repository based on contributions.

collaborate

  • Gitalk is a modern comment component based on Github Issue and Preact.
  • git-bug: Distributed, offline-first bug tracker embedded in git, with bridges

self-hosted

  • Gitlab, 可自建的Git服务器,web可视化界面、操作便捷,适合公司/团体使用
    • GitLab architecture
    • Running GitLab in a memory-constrained environment
    • 自建 Docker 版本,端口映射内外不一致时(容器内部端口为默认), 项目页面点击 clone 按钮后的 URL 展示问题
      • 假设:--publish 8443:443 --publish 8080:80 --publish 8022:22
      • 编辑配置 vi /etc/gitlab/gitlab.rb
      • 选项 Clone with SSH 下的 URL
        • gitlab_rails['gitlab_shell_ssh_port'] = 8022
      • 选项 Clone with HTTP[S] 下的 URL
        • 修改 external_url 并带上端口(如果 docker 启动时未设置正确的话)
        • 重写 nginx['listen_port'] = 80(如不重写此端口,将会根据 external_url 改变监听端口)
      • gitlab-ctl reconfigure
  • Gogs is a painless self-hosted Git service https://gogs.io
  • gitea Git with a cup of tea, painless self-hosted git service https://gitea.io
  • onedev Super Easy All-In-One DevOps Platform

others

  • Gource is a visualization tool for source control repositories.

FAQs

  • svn 迁移到 git
  • 换行符 CRLF 问题
    • Q 换行符自动转换
    • A 换行符问题 - Git权威指南
      • 不要手动去设置 core.autocrlf,默认即可(linux,macosxfalse, wintrue)
      • 设置: git config --global core.safecrlf true
      • 特别需求添加 .gitattributes 去约束
        • 由于 wintrue,会对文本文件自动添加 CR,如不希望此行为,将其视为二进制文件
  • push卡住的问题
    • Q push时卡在write objects.后续报fatal:The remote end hung up unexpectedly
    • A 问题原因是http.postBuffer默认上限为1M所致。将上限设为500M:
      git config --global http.postBuffer 524288000
      
  • gitlab fetch/pull 失败
  • 解决冲突出错
    • git reset --hard 无效
      fatal: Unable to create '/.git/index.lock': File exists.
      If no other git process is currently running, this probably means a
      git process crashed in this repository earlier. Make sure no other git
      process is running and remove the file manually to continue.
      
    • How do I fix a failed git commit?
      Removing index.lock file manually from .git directory worked.
      or From command line:
      $ rm -rf .git/index.lock
      Note: Make sure that only one index file exist on .git directory
  • office文档的diff方案
  • Pushing to Multiple Git Repos
  • How to restore a deleted branch
  • 重命名某个文件时,仅改变大小写问题。如:a.c -> A.c
    1. 备份并删除 a.c 提交;添加并提交 A.c
    2. git mv a.c A.c
  • 本地 repo 瘦身 git reflog expire --expire=now --all && git gc --prune=now --aggressive
  • clean history and re-init
    git checkout --orphan latest_branch
    git add -A
    git commit -am "init"
    git branch -D master
    git branch -m master
    git push -f origin master
    
  • Push an existing folder
    cd existing_folder
    git init --initial-branch=main
    git remote add origin XXXURL
    git add .
    git commit -m "Initial commit"
    git push -u origin main
    
  • Unload submodule from project but not remove/delete it.
    • git submodule deinit -f SUB_PATH