git

DESCRIPTION

The git is source code version control software.

  1. install git, example Ubuntu/Debian.

    $ sudo apt install git
  2. Configure personal information

    $ git config --global user.name "Your Name Comes Here"
    $ git config --global user.email you@yourdomain.example.com
  3. Check personal information

    $ git config -l

IMPORTING A NEW PROJECT

init git repositories

$ git init .

add files that want to trace

$ git add <files>

commit files to git repositories for tracing

$ git commit -m '

VIEWING PROJECT HISTORY

MANAGING BRANCHES

Review branch

Create new branch from the current tag/commit

Create new branch from the previous commit of a commit

Checkout branch

Delete branch

Modify branch name

REMOTE

The remote server has github, gitlab, gitee and private git server.

Clone remote server git repositories

Push code/tags to remote server

Pull code/tags from remote server

PATCH

output <commit> patch only

Output the patch of a certain range, such as the patch of commit1~commit3, excluding commit1 patch

output all patches of a file

see if the patch is applicable to the current working tree and/or the index file and detects errors. Turns off apply.

apply patch to git repositories

SUB-MODULES

Add sub-modules into a repository

Cloning a repository that contains submodules

Update sub-modules

Hooks

git hooks 是 git 的一个重要特性,它让你可以在Git仓库中定义一些自动化的脚本,这些 脚本可以在特定的Git事件(如提交代码、接收代码等)发生时被触发执行。 它们是在 Git仓库目录中的 .git/hooks/ 下的一组可执行文件。

  1. pre-commit

    • 触发时机: 在用户输入提交信息之前,执行 git commit 命令时触发。

    • 功能: 检查即将提交的内容。

    • 使用场景:

      • 运行代码风格检查(如 eslint, pylint, rubocop)。

      • 检查是否有调试语句(如 console.log, print)被意外提交。

      • 检查是否包含敏感信息(如密码、密钥)。

      • 检查文件命名规范、编码规范等。

  2. prepare-commit-msg

    • 触发时机: 在默认提交信息被创建之后,但在编辑器启动让用户编辑信息之前触发。

    • 功能: 修改提交信息。

    • 使用场景:

      • 自动将当前分支名、工单号(JIRA)等信息注入到提交信息模板中。

  3. commit-msg

    • 触发时机: 在用户编辑完提交信息之后触发。

    • 功能: 验证提交信息的格式和内容。

    • 使用场景:

      • 强制要求提交信息遵循特定格式。

      • 检查提交信息是否包含必要的工单号或关键字。

      • 确保提交信息描述达到最小长度要求。

  4. post-commit

    • 触发时机: 在整个提交过程完成之后触发。

    • 功能: 主要用于通知或其他不影响提交本身的操作。

    • 使用场景:

      • 触发通知(如发送邮件、Slack 消息告知有新提交)。

      • 更新项目文档或生成变更日志草稿。

EMAIL

  1. Shell 终端能够访问 gmail 服务器

  2. 安装 git send-email 功能,执行 $ apt install git-email

  3. 配置 git send-email 功能,参考 $ git help send-emailEXAMPLES 小节,

完成后,就能够使用 $ git send-email 进行发送邮件

如果想要给 Linux Kernel 提交 patch,需要按照以下步骤来执行:

  1. 修改源码,编译运行,测试,确保能够正常运行 patch 对应的功能

  2. 提交源码,如下:

  3. 生成 patch

将与 origin/master 不同的 commit 都生成 patch,存储在 patch/ 目录下

可选:

  • --cover-letter :生成以 0000- 为前缀的邮件封面,需要指定标题、简介。

  • -v <version> :指定新版本 注意:第二版本后的邮件封面,除了需要指定标题、简介外, 还需要写 版本改变日志、之前的版本在 https://lore.kernel.org 的链接

  • --base=auto :显示是基于哪一个 commit 进行修改

  • --subject-prefix="RFC PATCH": 生成 RFC PATCH 前缀,默认是 PTACH 前缀

  1. 通过 ./scripts/checkpatch.pl xxx.patch 检查 patch 格式是否符合要求

  2. 通过 ./scripts/get_maintainer.pl xxx.patch 获得 maintainer 邮箱地址

  3. 通过 git send-email --to xxx --cc xxx xxx.patch 来发送 patch 给 maintainer。 如果需要发送给多个邮箱地址,用 , 作为分隔符。如果是 patchset,发送时选择 a[ll]

TIPS

tag

look for string

compare differ branch

let's some commit of other branch to current branch

get files of some commit of other branch

When you develop a feature, commit multiple changes through git commit. If you want to merge this change into a single commit, you may do so through git rebase

The remote repository has new commits, but the local repository also has new commits. How to synchronize the new commits of the remote repository to the local repository?

When we need to actively merge new feature branches

Displays the commit of each line of a file

当我们想要知道 commit A 是在哪一个新merge feature合入时, 如何找到对应的merge commit ?

https://blog.csdn.net/qq_39734650/article/details/116658540

当我们想要研究某一个新merge feature时,merge commit 会显示feature commit范围, 比如 (A,F],其中不包括A,包括F。如何显示此feature所有commit ?

显示 commit A 是在哪一个版本被引入?

将一个已经 commit 的 patch 拆分成多个 patch,如下:

查看某个版本的文件内容,如下:

查看 [HEAD, v6.9) 范围之间的所有合并提交,如下:

查看 [HEAD, v6.9) 范围之间的所有真正提交,如下:

查看某个 commit xxx 的上一个提交,如下:

查看文件 mm/vmscan.c 第 1169 行的提交历史,如下:

查看文件 mm/vmscan.c1169~1190 行,在 v6.6~v6.12 的提交历史,如下:

Last updated

Was this helpful?