为什么Git不允许我快进合并了?如果我试图使用——ff-only强制它,我会得到消息“致命:不可能快进,终止。”我意识到合并-no-ff有巨大的优势,但我只是不明白为什么我现在不能-ff-only ?
当前回答
我什么时候能看到这条信息?
当你运行git merge——ff-only <some/branch>或git pull——ff-only <remote> <some/branch>时,你试图合并的分支或提交不是基于你当前的分支——它的历史以某种方式从你的分支分叉。
Git pull可以在配置中设置默认值,所以如果你运行一个简单的Git pull origin <some/branch>,你也可以看到这一点,并且你的配置有pull。Ff = only。 要检查你的配置:运行git config pull.ff 或者git config——show-origin pull.ff (git merge有一个类似的merge。ff选项)
我怎么才能知道什么东西不管用?
要查看你的分支和目标分支的历史,你可以使用:
git log --graph --oneline HEAD <some/branch>
如果你没有显式地输入一个分支名称(例如:git merge—ff-only或git pull—ff-only), git默认为“你的活动分支的上游分支”——通常是origin/mybranch。从命令行引用该分支的方法是@{u}:
git log --graph --oneline HEAD @{u}
# for Powershell users: @{...} is an operator, you will need to quote "@{u}"
git log --graph --oneline HEAD "@{u}"
您应该看到当前分支和目标分支之间的分歧。 参见下面的“更多git日志选项”。
我该怎么补救呢?
这取决于你想要达到的结果,以及你在上面的历史中看到的结果。
你可能想要在目标提交的基础上重新构建你的提交:
git rebase <some/branch>
# to rebase on top of your default upstream :
git rebase # same as 'git rebase @{u}'
你可能想要运行一个实际的合并,而不是只允许快进:
git merge <some/branch>
git merge # same as 'git merge @{u}'
或者任何符合你需要的东西:
在远程分支的顶部挑选一些你的提交, 使用git rebase -i, 以另一种方式合并……
当我跑的时候如何避免这种情况?
如果你设置了——ff-only作为默认值(例如:If git config pull. only)。Ff只返回),你可以通过显式地提供一个命令行标志来一次性覆盖这个默认值:
git pull --rebase # rebase on top of fetched branch, rather than merge it
git pull --ff # run a normal merge
# (note: you *will* have a merge commit in your history)
如果你想将默认值更改为其他值:
# remove that default value, allow normal merges when pulling
git config --global --unset pull.ff
# run `git pull --rebase` by default
# note: you still need to run 'git config --global --unset pull.ff'
git config --global pull.rebase true
更多git日志选项
要查看终端中两个分支之间的差异:
Git log -oneline -graph a b将向您显示a和b结合在一起的完整历史。 如果你想知道a和b分叉后的历史:
git log --oneline --graph --boundary a...b
# a...b (3 dots) : means 'symmetric difference' in git log
# --boundary : will show the commit that was at the fork point
# without this option, the two histories will be printed
# one below the other
如果你想隐藏分支——例如,如果你想查看git log my/branch…Master,但不想查看所有合并到Master的pull请求的详细信息:
git log --oneline --graph --boundary --first-parent a...b
# --first-parent : on merge commits, only follow the first parent
许多git的图形前端(Gitextensions, TortoiseGit, gitk…)在查看存储库历史记录时都有方法激活这些选项。 在您的GUI中寻找复选框,以及您可以键入…b或HEAD…@{u}。
如果你打算经常使用这些命令,为它们设置一个别名:
# example: show HEAD vs @{upstream} log
git config --global alias.whatsup 'log --oneline --graph --boundary HEAD...@{u}'
# you can now run:
git whatsup
其他回答
尝试一下,会工作得很好----
Git拉原点-rebase
使用选项——no-ff关闭一次快进:
git pull --no-ff
https://git-scm.com/docs/git-pull#Documentation/git-pull.txt---no-ff
git pull origin main --rebase
git pull --rebase
以上两个命令对我很有用。但唯一的问题是,我在当前分支中也看到了主分支的提交..
对我来说,这是有效的,改变branch_name与实际的分支:
git pull origin branch_name --no-ff
If
git pull
不做的把戏,如果你想合并当前的变化和变化将来自分支从原点拉,然后这样做:-
git merge origin/BRANCH_NAME
之后,解决合并冲突,如果有的话,这一天就结束了。
推荐文章
- 为什么我需要显式地推一个新分支?
- 如何撤消最后的git添加?
- Rubymine:如何让Git忽略Rubymine创建的.idea文件
- Gitignore二进制文件,没有扩展名
- Git隐藏错误:Git隐藏弹出并最终与合并冲突
- 了解Git和GitHub的基础知识
- 没有。Git目录的Git克隆
- Git与Mercurial仓库的互操作性
- 忽略git中修改(但未提交)的文件?
- “git restore”命令是什么?“git restore”和“git reset”之间有什么区别?
- Git合并与强制覆盖
- Git拉另一个分支
- 在Bash命令提示符上添加git分支
- 如何更改Git日志日期格式
- git pull -rebase和git pull -ff-only之间的区别