Appearance
graph
Git 移动指针,可以切换版本。
- 初始提交没有父提交
- 普通提交有一个父提交
- 合并提交有多个父提交
避免多个父提交,Git 提交成线型,方便以后理解。
初始化
git init test
cd test
echo 'Hello World' > hello.txt
git add .
git commit -m '初始化'Initialized empty Git repository in ~/test/.git/
[master (root-commit) *******] 初始化
1 file changed, 1 insertion(+)
create mode 100644 hello.txt三个分支
git branch feature-a
git branch feature-b
git branch feature-c
# 第一个分支
git switch feature-a
echo 'Hello Human' > a.txt
git add .
git commit -m 'new a.txt'
# 第二个分支
git switch feature-b
echo 'Hello Animals' > b.txt
git add .
git commit -m 'new b.txt'
# 第三个分支
git switch feature-c
echo 'Hello Robot' > c.txt
git add .
git commit -m 'new c.txt'
# 合并分支
git switch master
git merge feature-a feature-b feature-c -m '合并分支 feature-a feature-b feature-c'
git log --graph --oneline[feature-a *******] new a.txt
1 file changed, 1 insertion(+)
create mode 100644 a.txt
[feature-b *******] new b.txt
1 file changed, 1 insertion(+)
create mode 100644 b.txt
[feature-c *******] new c.txt
1 file changed, 1 insertion(+)
create mode 100644 c.txt
Fast-forwarding to: feature-a
Trying simple merge with feature-b
Trying simple merge with feature-c
Merge made by the 'octopus' strategy.
a.txt | 1 +
b.txt | 1 +
c.txt | 1 +
3 files changed, 3 insertions(+)
create mode 100644 a.txt
create mode 100644 b.txt
create mode 100644 c.txt
*-. ******* 合并分支 feature-a feature-b feature-c
|\ \
| | * ******* new c.txt
| * | ******* new b.txt
| |/
* / ******* new a.txt
|/
* ******* 初始化