← 返回命令列表

Linux command

git-subtree 命令

安全

权限或系统影响较大,执行前请核对目标。

常用示例

Add subtree

git subtree add --prefix=[dir] [repo] [branch]

Pull subtree changes

git subtree pull --prefix=[dir] [repo] [branch]

Push subtree changes

git subtree push --prefix=[dir] [repo] [branch]

Split subtree

git subtree split --prefix=[dir] -b [new_branch]

Merge subtree

git subtree merge --prefix=[dir] [commit]

说明

git subtree merges and splits repositories into subdirectories, providing an alternative to submodules. Unlike submodules, subtrees keep everything in a single repository with a unified history. The `split` command extracts the history of a subdirectory into a separate branch, while `add`, `pull`, and `push` manage the ongoing synchronization with the upstream repository.

参数

--prefix _dir_
Subdirectory for subtree.
--squash
Squash history.
-b _branch_
Branch name for split.

FAQ

What is the git-subtree command used for?

git subtree merges and splits repositories into subdirectories, providing an alternative to submodules. Unlike submodules, subtrees keep everything in a single repository with a unified history. The `split` command extracts the history of a subdirectory into a separate branch, while `add`, `pull`, and `push` manage the ongoing synchronization with the upstream repository.

How do I run a basic git-subtree example?

Run `git subtree add --prefix=[dir] [repo] [branch]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does --prefix _dir_ do in git-subtree?

Subdirectory for subtree.