git subtree push --squash不会压扁 [英] git subtree push --squash does not squash
问题描述
我使用 git subtree
来组织我的git存储库。比方说,我有一个名为 repo
的主存储库和一个名为 lib
的库。
通过压缩其历史记录,我成功导入了 lib
存储库。我现在想通过压缩历史来回馈 lib
。这似乎并不奏效:我在 git subtree push
中指定了 - squash
选项,但是在查看历史记录时我仍然发送所有提交。
如何重现
以下是一个脚本,重现问题:
#!/ bin / bash
rm -rf lib lib-work回购
#repo是主存储库
git init repo
#lib是'subtreed'存储库(bare to accept pushes)
git init --bare lib
git clone lib lib-work
cd lib-work
#向lib提供一堆提交
echov1> README
git add README
git commit -m'lib commit 1'
echov2> README
git add README
git commit -m'lib commit 2'
echov3> README
git add README
git commit -m'lib commit 3'
git push origin master
cd ..
cd repo
#添加初始提交以拥有有效的HEAD
echov1> README
git add README
git commit -m'repo commit 1'
git remote add lib ../lib
git subtree add --prefix lib lib master --squash
回声v4> lib / README
git add lib / README
git commit -m'repo commit 2'
echov5> lib / README
git add lib / README
git commit -m'repo commit 3'
echov6> lib / README
git add lib / README
git commit -m'repo commit 4'
#git log --all --color --graph --pretty = format:'%Cred %h%Creset - %C(黄色)%d%Creset%s%Creset'--abbrev-commit
#not workingcommand:
git subtree push --prefix lib lib master - 壁球
#漂亮打印历史
git log --all --color --graph --pretty = format:'%Cred%h%Creset - %C(yellow)%d %Creset%s%Creset'--abbrev-commit
cd ../lib
echo
git log --all --color --graph --pretty = format:'%Cred %h%Creset - %C(黄色)%d%Creset%s%Creset'--abbrev-commit
git log 显示问题
两个 git log blabla的输出
命令是:
* b075d5e - (HEAD,master)repo commit 4
* ebdc7c7 - repo commit 3
* 9f1edab - repo commit 2
* 3d48bca - 合并提交'34e16a547819da7e228f3add35efe86197d2ddcb'as'lib'
| \
| * 34e16a5 - 从提交2643625压缩'lib /'内容
* 3f1490c - repo commit 1
* 1f86fe3 - (lib / master)repo commit 4
* 9f1639a - repo commit 3
* 8bd01bd - repo commit 2
* 2643625 - lib commit 3
* 3d64b8c - lib commit 2
* aba9fcb - lib commit 1
和:
* 1f86fe3 - (HEAD,master) repo commit 4
* 9f1639a - repo commit 3
* 8bd01bd - repo commit 2
* 2643625 - lib commit 3
* 3d64b8c - lib commit 2
* aba9fcb - lib commit 1
正如您所看到的,lib会看到repo commit 2 ,3,4
虽然我指定了压扁选项。
另一种解决方法是从$ f28bf8e 中压缩压扁的'lib /'内容。
在git 1.8.1.msysgit.1和linux git 1.8.3.4上试过。
那么为什么不是 --squash
选项做一个压扁? 侧面问题
/ master出现在 repo
存储库的日志中?
在失败 git push
之后知道它只出现 :如果取消注释第一个 git log blabla
您将得到以下输出,显示存储的历史记录,但没有lib / master的标志:
* b075d5e - (HEAD,master)repo commit 4
* ebdc7c7 - repo commit 3
* 9f1edab - repo commit 2
* 3d48bca - 合并提交'34e16a547819da7e228f3add35efe86197d2ddcb'as'lib'
| \
| * 34e16a5 - 从提交2643625压缩'lib /'内容
* 3f1490c - repo commit 1
有可能这是subtree命令文档中的错误。
git中的手册指出: p>
'add','merge','pull'和'push'的选项
--squash合并子树更改为一次提交
如果您在原始子树项目,您会注意到 - squash
选项仅针对添加
和 merge
进行解释,因为该功能描述了将内容进入你的仓库。由于 pull
是一种经过修改的合并形式,因此也暗示它可以使用 - squash
。
手动列表中的 push
不合理。 git子树push
子命令是 git子树split
和 git push
。这意味着 - squash
应该也是由 split
支持的一个选项,但是 split
未在手册列表中列出。它在文档中从未声明它可以使用 - squash
。
- squash
选项确实被 split
和 push
接受,但没有错误试验它,它看起来没有什么区别,就像你的例子所说的那样。我的看法是,它出错了,被 split
和 push
命令所忽略。
I am using git subtree
to organize my git repositories. Let's say I have a main repository called repo
and a library called lib
.
I successfully "imported" the lib
repository by squashing its history. I would now like to contribute back to lib
by squashing the history too. This does not seem to work: I specify the --squash
option to git subtree push
but when looking at the history I still send all the commits.
How to reproduce
Here is a script showing the minimal commands needed to reproduce the problem:
#!/bin/bash
rm -rf lib lib-work repo
# repo is the main repository
git init repo
# lib is the 'subtreed' repository (bare to accept pushes)
git init --bare lib
git clone lib lib-work
cd lib-work
# adding a bunch of commits to lib
echo "v1" > README
git add README
git commit -m 'lib commit 1'
echo "v2" > README
git add README
git commit -m 'lib commit 2'
echo "v3" > README
git add README
git commit -m 'lib commit 3'
git push origin master
cd ..
cd repo
# adding initial commit to have a valid HEAD
echo "v1" > README
git add README
git commit -m 'repo commit 1'
git remote add lib ../lib
git subtree add --prefix lib lib master --squash
echo "v4" > lib/README
git add lib/README
git commit -m 'repo commit 2'
echo "v5" > lib/README
git add lib/README
git commit -m 'repo commit 3'
echo "v6" > lib/README
git add lib/README
git commit -m 'repo commit 4'
#git log --all --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s%Creset' --abbrev-commit
# "not working" command :
git subtree push --prefix lib lib master --squash
# pretty print the history
git log --all --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s%Creset' --abbrev-commit
cd ../lib
echo
git log --all --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s%Creset' --abbrev-commit
git log
showing the problem
The output of the two git log blabla
commands are:
* b075d5e - (HEAD, master) repo commit 4
* ebdc7c7 - repo commit 3
* 9f1edab - repo commit 2
* 3d48bca - Merge commit '34e16a547819da7e228f3add35efe86197d2ddcb' as 'lib'
|\
| * 34e16a5 - Squashed 'lib/' content from commit 2643625
* 3f1490c - repo commit 1
* 1f86fe3 - (lib/master) repo commit 4
* 9f1639a - repo commit 3
* 8bd01bd - repo commit 2
* 2643625 - lib commit 3
* 3d64b8c - lib commit 2
* aba9fcb - lib commit 1
and :
* 1f86fe3 - (HEAD, master) repo commit 4
* 9f1639a - repo commit 3
* 8bd01bd - repo commit 2
* 2643625 - lib commit 3
* 3d64b8c - lib commit 2
* aba9fcb - lib commit 1
As you can see, lib sees the "repo commit 2,3,4"
although I specified the squash option.
The other way around worked hence the Squashed 'lib/' content from commit f28bf8e
.
I tried on windows with git version 1.8.1.msysgit.1 and on linux with git version 1.8.3.4.
So why doesn't the --squash
option do a squash?
Side question
Why does lib/master appears in the log of the repo
repository ?
Knowing it appears only after the "failed" git push
: if you uncomment the first git log blabla
you get the following output showing the stashed history but no sign of lib/master :
* b075d5e - (HEAD, master) repo commit 4
* ebdc7c7 - repo commit 3
* 9f1edab - repo commit 2
* 3d48bca - Merge commit '34e16a547819da7e228f3add35efe86197d2ddcb' as 'lib'
|\
| * 34e16a5 - Squashed 'lib/' content from commit 2643625
* 3f1490c - repo commit 1
It is possible that this is an error in the documentation of the subtree command.
The manual in git states:
options for 'add', 'merge', 'pull' and 'push'
--squash merge subtree changes as a single commit
If you check the more extended documentation in the original subtree project you will notice that the --squash
option is only explained for add
and merge
, as the functionality is described for the process of bringing content into your repository. Since pull
is a modified form of merge, it is also implied that it can use --squash
.
The push
in the manual list what does not make sense. The git subtree push
subcommand is a combination of git subtree split
and git push
. This means that --squash
should be an option also supported by split
, but split
is not listed in the manual list. It is neither ever stated in the documentation that it can use --squash
.
The --squash
option is indeed accepted by split
and push
without error, but after experiment with it it seems it makes no difference, just as your example states. My take is that it is there by mistake and just ignored by the split
and push
commands.
这篇关于git subtree push --squash不会压扁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!