- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
在处理功能分支时,我使用此 Git 命令将我的“开发”分支更新到最新状态,然后立即将我的功能分支与“开发”分支 merge :
git fetch origin develop:develop
这行得通,即本地“develop”指向与“origin/develop”相同的提交,并且处于 origin 的最新状态。
但是,不知何故,当 checkout “develop”分支时,此命令失败:
fatal: Refusing to fetch into current branch refs/heads/develop of non-bare repository
fatal: The remote end hung up unexpectedly
如果我知道为什么会这样,那将有助于我更好地理解 Git。
最佳答案
错误信息来自builtin/fetch.c#check_not_current_branch()
.
该函数一直追溯到 commit 8ee5d73, Oct. 2008, git 1.6.0.4 .
(另请参阅“Git refusing to fetch into current branch ”)。
评论很有启发性:
Some confusing tutorials suggested that it would be a good idea to fetchinto the current branch with something like this:
git fetch origin master:master
(or even worse: the same command line with "pull" instead of "fetch").
While it might make sense to store what you want to pull, it typically isplain wrong when the current branch is "master
".
This should only be allowed when (an incorrect) "git pull origin master:master
" tries to work around by giving--update-head-ok
to underlying "git fetch
", and otherwise we should refuse it, but somewhere along the lines we lost that behavior.The check for the current branch is now only performed in non-barerepositories, which is an improvement from the original behaviour.
考虑到函数 check_not_current_branch()
是 called with :
if (!update_head_ok)
check_not_current_branch(ref_map);
这意味着 git fetch -u origin develop:develop
应该可以工作。
-u
--update-head-ok
By default git fetch refuses to update the head which corresponds to the current branch. This flag disables the check.
This is purely for the internal use forgit pull
to communicate withgit fetch
, and unless you are implementing your own Porcelain you are not supposed to use it.
即使您不应该使用该选项,它也确实满足了您的初始要求,使“git fetch origin branch:branch
”在当前 分支上工作。
关于这个补丁的来源,follow the discussion there .
While it might make sense to store what you want to pull
那是 fetch
部分:它存储来自更新后的 origin/master
的远程历史。
但当当前本地分支也是 master
时,这种情况尤其严重。
如前所述 in this answer :
I think "
git fetch url side:master
" whenmaster
is the current branchand we have omitted--update-head-ok
is broken.
The test fails on currentmaster
.It would also fail to update the working directory and would leavethe index as if you're removing everything.
以“git pull
with refspec”为例。
torek 显示了一个示例,其中:
suppose that I run git fetch and it brings in two new commits that I will label
C
andD
.C
's parent isA
, andD
's is the node just beforeB
:C
/
...--o--o--A <-- master
\
o--B <-- develop
\
DThe output from this git fetch will list this as:
aaaaaaa..ccccccc master -> origin/master
+ bbbbbbb...ddddddd develop -> origin/develop (forced update)
如果您当前的分支不是 develop
,那么强制更新可能就是您想要的。
但是,如果您在上 develop
时键入git fetch origin develop:develop
,并且允许获取更新 HEAD,...那么您当前的索引将反射(reflect) D
,而不再是 B
。
因此,在您的工作树中完成的 git diff
将显示您的文件和 D
之间的差异,而不是您之前的 HEAD B
。
这很糟糕,因为您最初的 git checkout develop
创建了一个与 B
HEAD 文件相同的工作树。
即使你的 git status
是干净的(没有任何类型的修改),如果 git fetch origin develop:develop
更新了 HEAD(强制从 B 更新到 D),git status
现在会报告在获取之前没有差异的地方。
这就是为什么默认情况下 git fetch
拒绝更新对应于当前分支的头部。
注意:Git 2.29 中的一个错误也会触发类似的错误消息。
当“git commit-graph
”( man ) 在 merge 层时检测到同一提交记录不止一次时,它曾经死掉。
该代码现在忽略除其中一个之外的所有内容并继续,已在 Git 2.30(2021 年第一季度)中修复。
参见 commit 85102ac , commit 150f115 (2020 年 10 月 9 日)Derrick Stolee (derrickstolee
) .
(由 Junio C Hamano -- gitster
-- merge 于 commit 307a53d,2020 年 11 月 2 日)
commit-graph
: ignore duplicates when merging layersReported-by: Thomas Braun
Helped-by: Taylor Blau
Co-authored-by: Jeff King
Signed-off-by: Derrick Stolee
Thomas reported that a "
git fetch
"(man) command was failing with an error saying "unexpected duplicate commit id".$ git fetch origin +refs/head/abcd:refs/remotes/origin/abcdfatal: unexpected duplicate commit id31a13139875bc5f49ddcbd42b4b4d3dc18c16576
The root cause is that they had
fetch.writeCommitGraph
enabled which generatescommit-graph
chains, and this instance was merging two layers that both contained the same commit ID.The initial assumption is that Git would not write a commit ID into a
commit-graph
layer if it already exists in a lowercommit-graph
layer.
Somehow, this specific case did get into that situation, leading to this error.While unexpected, this isn't actually invalid (as long as the two layers agree on the metadata for the commit). When we parse a commit that does not have a
graph_pos
in thecommit_graph_data_slab,
we use binary search in thecommit-graph
layers to find the commit and setgraph_pos
.
That position is never used again in this case. However, when we parse a commit from thecommit-graph
file, we load its parents from thecommit-graph
and assigngraph_pos
at that point.
If those parents were already parsed from thecommit-graph
, then nothing needs to be done. Otherwise, thisgraph_pos
is a valid position in thecommit-graph
so we can parse the parents, when necessary.Thus, this
die()
is too aggressive. The easiest thing to do would be to ignore the duplicates.If we only ignore the duplicates, then we will produce a commit-graph that has identical commit IDs listed in adjacent positions. This excess data will never be removed from the
commit-graph
, which could cascade into significantly bloated file sizes.Thankfully, we can collapse the list to erase the duplicate commit pointers. This allows us to get the end result we want without extra memory costs and minimal CPU time.
The root cause is due to disabling
core.commitGraph
, which prevents parsing commits from the lower layers during a 'git commit-graph write --split
(man)' command.
Since we use the 'graph_pos
' value to determine whether a commit is in a lower layer, we never discover that those commits are already in thecommit-graph
chain and add them to the top layer. This layer is then merged down, creating duplicates.The test added in
t5324-split-commit-graph.sh
fails without this change. However, we still have not completely removed the need for this duplicate check. That will come in a follow-up change.
和:
commit-graph
: don't write commit-graph when disabledReported-by: Thomas Braun
Helped-by: Jeff King
Helped-by: Taylor Blau
Signed-off-by: Derrick Stolee
The
core.commitGraph
config setting can be set to 'false
' to prevent parsing commits from thecommit-graph
file(s). This causes an issue when trying to write with "--split
" which needs to distinguish between commits that are in the existingcommit-graph
layers and commits that are not.
The existing mechanism usesparse_commit()
and follows by checking if there is a 'graph_pos
' that shows the commit was parsed from thecommit-graph
file.When
core.commitGraph=false
, we do not parse the commits from thecommit-graph
and 'graph_pos
' indicates that no commits are in the existing file.
The--split
logic moves forward creating a new layer on top that holds all reachable commits, then possibly merges down into those layers, resulting in duplicate commits. The previous change makes that merging process more robust to such a situation in case it happens in the writtencommit-graph
data.The easy answer here is to avoid writing a
commit-graph
if reading the commit-graph is disabled. Since the resultingcommit-graph
will would not be read by subsequent Git processes. This is more natural than forcingcore.commitGraph
to betrue
for the 'write
' process.
git commit-graph
现在包含在其 man page 中:
Write a
commit-graph
file based on the commits found in packfiles. Ifthe config optioncore.commitGraph
is disabled, then this command willoutput a warning, then return success without writing acommit-graph
file.
关于git - 为什么 "git fetch origin branch:branch"只适用于非当前分支?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29028696/
我使用 Git 有一段时间了,但尽管在博客和教程上花了很多时间,但我仍然无法理解某些功能...:) 我正在与其他人合作一个项目,我的老板为此在 bitBucket 上创建了一个存储库。 我在本地克隆了
有时我会遇到以下问题: 在功能分支中添加一些提交。 从上游更新 master。 想要查看功能分支和 master 之间的差异,但是 git diff master 显示了在 master 中添加/删除
我使用的是 Gerrit 2.4.2 版。我有一个分支 master,我创建了一个名为 newbranch 的新分支。然后我将一些更改推送到远程(Gerrit 的)newbranch。在 Gerrit
假设我们有一个远程存储库并在本地克隆它。 我们 checkout master 分支,所以现在我们有本地 master 和一个 Remote remotes/origin/master . 然后我必须
我有一个项目,其中开发分支使用 CocoaPods,但其中一位开发人员决定删除它并改用 Carthage。 feature 分支使用的是 CocoaPods,因为它是在 develop 分支转换之前一
我有一个有问题的 master 分支需要调试。为此,我想插入一堆调试程序(例如,打印变量),查明错误并应用修复程序。稍后,我想将修复 merge 到 master 分支中,但我不想跳过调试更改。 #
我有一个 master 分支,我正在其中 push 我的最新开发。 现在在某个时候,我确实从 master 分支发布并创建了名为 release1 的新分支。 现在我在master分支上做新的开发 与
我正在尝试使我的一些标准工作流程自动化,我发现自己经常做的一件事是将对远程 master 分支的更改 merge 到我自己的本地分支并推送结果。 所以步骤如下: 转为大师 从远程 pull 更改 切换
使用 Gerrit 很容易意外地将开发分支中的不稳定代码 merge 到稳定分支中: $ git checkout develop $ commit $ git push origin HEAD:re
我有一个正在进行的项目,我正在雇用承包商来帮助我处理代码的某些部分。问题是我不想让任何一个承包商看到所有这些。 我可以在 GitHub 上为他们分配私有(private)存储库下的分支吗?这需要命令行
SVN 分支 Branch 选项会给开发者创建出另外一条线路。当有人希望开发进程分开成两条不同的线路时,这个选项会非常有用。我们先假设你已经发布了一个产品的 1.0 版本,你可能想创建一个新的分支,
关闭。这个问题是opinion-based .它目前不接受答案。 想改进这个问题?更新问题,以便 editing this post 提供事实和引用来回答它. 2年前关闭。 Improve this
有没有办法从特定的修订版中创建(svn)分支, 因为我想跳过提交历史中的一些修订(在新分支中)。 例如,我有从 1 到 1590 的修订,我想创建一个新分支并跳过提交(从 1504 到 1574 )和
到目前为止我看到的所有 svn 分支的例子都是这样的 svn cp -m 'Making test branch' svn://svnrepo/hellosite svn://svnrepo/hell
当我尝试使用 Sonar 扫描仪分析我的项目时,扫描失败并显示以下错误消息: Caused by: Branch does not exist on server: develop 显然,这只发生在它
在我的 Mercurial 存储库中,不知何故,有人输入了空白分支名称: 如果我hg id -r 2004,我确实得到空白文本。现在的问题是,这会导致我们的Redmine安装出现问题,因为它无法同步存
我有以下代码片段: srcaddr >= inet_ntoa . fromJust dstaddr >= inet_ntoa . fromJust -- I want to perform actio
在我的项目中,我有用于工作的本地分支和网络驱动器上的分支我在本地一号和网络一号之间做了“绑定(bind)分支”我的想法是使用绑定(bind)选项自动备份每个本地提交。 我在本地分支提交文件后,我在网络
我想创建一个脚本,根据变量的状态使用不同的表和命令执行不同的操作。在 T-SQL 中,我会这样做: DECLARE @whatToDo INT = 1; IF @whatToDo = 1 BEGIN
Write a program that reads input up to # and reports the number of times that the sequence ei occurs
我是一名优秀的程序员,十分优秀!