吉特。 git repos 的 svn dcommit 模拟

发布于 2024-11-23 16:48:08 字数 368 浏览 0 评论 0原文

我想使用下一个典型的工作流程:

  1. 为功能创建新分支,并签出它
  2. 在功能分支中的提交
  3. ,签出主
  4. 合并与功能分支。
  5. 推送更改

这是非常典型的用例。 然而,有一件事让我烦恼——我不想向公众展示我的分支的承诺。我只想推送合并提交,没有功能开发历史。

人们可以建议使用 git rebase 来压缩提交。但事实上,这种挤压只是一种变通办法,而不是真正的解决方案。我希望将所有提交都放在本地,合并图表,以用于历史记录。

我想要得到与 git svn dcommit 类似的结果 - 仅合并提交被推送到远程,但我看到本地的整个开发历史,包括功能提交、双父合并节点和适当的合并图。

I want to use next typical workflow:

  1. create new branch for feature, and checkout it
  2. do commits in feature branch
  3. checkout master
  4. merge with feature branch.
  5. push changes

It is very typical use case.
However, there is one thing that anoying me - I dont want to show my branch commits to public. I just want to push only merge commit, without feature developing history.

One can propose to use git rebase with commits squashing. But in fact, such squashing is just workaround, not a real solution. I want to have all my commits localy, merge graph, for history purposes.

I want to get simmilar that I get with git svn dcommit - only merge commit is pushed onto the remote, but I see localy whole history of development, with feature commits, with two-parents merge node and appropriate merge graph.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

任性一次 2024-11-30 16:48:08

您可以尝试

git merge --squash <feature branch>

这将执行您想要的所有操作,但分支实际上并未被视为合并。

You could try

git merge --squash <feature branch>

That will do everything you want with the exception of the branch's not actually being considered merged.

笑脸一如从前 2024-11-30 16:48:08

如果我理解正确的话,您希望进行一次提交(即一次 SHA1),但您希望它在存储库副本上的外观与在中央副本上的外观不同。

这样做是不可能的。 Git 的诞生使得这种方式变得不可能。如果您知道存储库中提交的 SHA1 id,则可以确保您了解其所有历史记录。

但是,有一种方法可以伪造这一点:使用移植。这样,您可以将父级添加到提交中,而无需实际修改它。虽然我不太确定这是一个好主意。

If I understand you correctly, you want to have one commit (i.e. one SHA1), but you want it to look differently on your copy of the repository than on on the central copy.

Doing that is just impossible. Git was made so that this way impossible. If you know a SHA1 id of a commit in a repository, you can be sure that you know all its history.

But, there is one way to fake that: using grafts. This way, you can add a parent to a commit without actually modifying it. Although I'm not really sure this is a good idea.

爱的十字路口 2024-11-30 16:48:08

根据您的评论,这是另一个解决方案:像平常一样在功能分支中进行工作。像平常一样,根据需要将功能分支合并到主分支中。在推送到远程之前,请执行压缩合并到单独的分支,然后将分支推送到远程。示例:

# Create two repos for testing
mkdir test-git-merging
mkdir test-git-merging2
cd test-git-merging2
git init
# Have to set this flag to be able to push with master checked out
git config receive.denyCurrentBranch ignore
cd ../test-git-merging
git init
# Base commit in first repo
git commit --allow-empty -m "init"
# Create the branch that will be pushed to the remote
git branch remote-master
# Make some files and commit them in master
echo foo >> foo
echo bar >> bar
git add .
git commit -m "added files"
# Make a change on a branch
git checkout -b branch
echo 1 >> foo
git commit -am "Modified foo"
# Make a non-conflicting change in master
git checkout master
echo 2 >> bar
git commit -am "Modified bar"
# Do a normal merge from branch to master--normal history
git merge branch
# Squash merge from master to special remote branch
git checkout remote-master
git merge --squash master
git commit -m "Everything is squashed"
# Set up the remote and push config
git remote add other ../test-git-merging2
git config branch.remote-master.remote other
git config branch.remote-master.merge master
git config push.default tracking
# Push the branch
git push

我已经测试了该命令序列以查看其是否有效。当然,分支远程主控仍然永远不会有真正的历史,这意味着将东西从它拉回您的工作分支总是很危险的,但这本质上就是您所要求的。

Based on your comments, here's another solution: Do your work in feature branches, like normal. Merge feature branches into master as needed, like normal. Before you push to the remote, do a squash merge to a separate branch, and push that branch to the remote. Example:

# Create two repos for testing
mkdir test-git-merging
mkdir test-git-merging2
cd test-git-merging2
git init
# Have to set this flag to be able to push with master checked out
git config receive.denyCurrentBranch ignore
cd ../test-git-merging
git init
# Base commit in first repo
git commit --allow-empty -m "init"
# Create the branch that will be pushed to the remote
git branch remote-master
# Make some files and commit them in master
echo foo >> foo
echo bar >> bar
git add .
git commit -m "added files"
# Make a change on a branch
git checkout -b branch
echo 1 >> foo
git commit -am "Modified foo"
# Make a non-conflicting change in master
git checkout master
echo 2 >> bar
git commit -am "Modified bar"
# Do a normal merge from branch to master--normal history
git merge branch
# Squash merge from master to special remote branch
git checkout remote-master
git merge --squash master
git commit -m "Everything is squashed"
# Set up the remote and push config
git remote add other ../test-git-merging2
git config branch.remote-master.remote other
git config branch.remote-master.merge master
git config push.default tracking
# Push the branch
git push

I've tested that sequence of commands to see that it works. Of course, the branch remote-master will still never have real history, meaning that it will always be dangerous to pull stuff back from it to your working branches, but that's essentially what you're asking for.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文