我想了解Git如何处理功能分支工作流中的以下情况:在主分支上删除文件,然后提交该删除。在功能分支上删除相同的文件并提交删除。然后主分支在功能分支上重新定位。
[user@host public]$ git status
# On branch master
nothing to commit (working directory clean)
[user@host public]$ git checkout -b master_test
Switched to a new branch 'master_test'
[user@host public]$ git checkout master
Switched to branch 'master'
[user@host public]$ git rm test.txt
rm 'public/test.txt'
[user@host public]$ git commit -m "Remove test file"
[master 0cfee96] Remove test file
0 files changed, 0 insertions(+), 0 deletions(-)
delete mode 100644 public/test.txt
[user@host public]$ git checkout master_test
Switched to branch 'master_test'
[user@host public]$ git rm test.txt
rm 'public/test.txt'
[user@host public]$ git commit -m "Remove test file on the feature branch"
[master_test f6468dc] Remove test file on the feature branch
0 files changed, 0 insertions(+), 0 deletions(-)
delete mode 100644 public/test.txt
[user@host public]$ git checkout master
Switched to branch 'master'
Your branch is ahead of 'origin/master' by 1 commit.
[user@host public]$ git rebase master master_test
First, rewinding head to replay your work on top of it...
Nothing to do.
[user@host public]$ git log -1
commit 0cfee962f7cab143d7a2835e0ecd50d8cef7230e
Author: leonard <leonard@host.co.uk>
Date: Mon Nov 9 10:47:28 2015 +0000
Remove test file
[user@host public]$ git branch
master
* master_test
Git是否乐意放弃Remove test file on the feature branch
提交,因为它认为它是一样的?它是否总是使用master中的一个提交覆盖功能分支提交(当以这种方式重新定位时)并且当与多个提交结合时会发生同样的事情吗?
答案 0 :(得分:2)
根据git rebase --help
:
请注意,HEAD中引入与HEAD中的提交相同的文本更改的任何提交都将被省略(即,将跳过已使用不同提交消息或时间戳的上游接受的修补程序)。
哪一个被覆盖取决于您在变基时选择的方向,即master
上的变焦master_test
,反之亦然。分支名称对git没有任何特殊含义。
根据手册页(any commits
),是的,在多次提交的情况下会发生同样的事情。
有点相关question。