Git的片状行为 - 没有提交?

时间:2017-03-22 18:09:42

标签: git

我尝试了" merge --no-commit",并忽略了--no-commit。为什么呢?

以下是发生的事情:

baria@DESKTOP-057K4L5 MINGW64 /c/repos/mobile-solutions (feature/create-new-theme)
$ git status
On branch feature/create-new-theme
Your branch is behind 'origin/feature/create-new-theme' by 1 commit, and can be fast-forwarded.
(use "git pull" to update your local branch)
nothing to commit, working directory clean

baria@DESKTOP-057K4L5 MINGW64 /c/repos/mobile-solutions (feature/create-new-theme)
$ git merge --no-commit origin/feature/create-new-theme
Updating 0010daa..d835f24
Fast-forward
.../Views/CarrierAccountLines/CarrierAccountLineMenu.cshtml         | 3 +--
src/Max.Web/wwwroot/master/sass/app2/custom/all.scss                | 6 ++++++
2 files changed, 7 insertions(+), 2 deletions(-)

baria@DESKTOP-057K4L5 MINGW64 /c/repos/mobile-solutions (feature/create-new-theme)
$ git status
On branch feature/create-new-theme
Your branch is up-to-date with 'origin/feature/create-new-theme'.
nothing to commit, working directory clean

我预计不会有任何承诺。我误解了什么?

1 个答案:

答案 0 :(得分:2)

git merge --no-commit won't create a merge commit会自动生成,但这仅适用于您要合并的两个分支实际需要合并提交的情况。

在这种情况下,您的分支可以是fast-forwarded,因此不会创建任何提交。

如果您检查历史记录git --log --graph --oneline --pretty --decorate,您将发现没有合并提交,并且您的分支的最后一次提交与您合并的最后一次提交相同。

如果您希望将来阻止这种情况发生,请将--no-ff添加到选项列表中;这将force Git to create a merge commit而不是没有合并提交。