Git 通过 svn - 管理文件

发布于 2024-09-12 17:12:48 字数 458 浏览 5 评论 0原文

也许我错过了一些关于通过 svn 使用 gi 的事情,但是我如何保留一组本地修改的文件而不将这些更改推送到 subversion。

这是我破碎的工作流程。

(在master上)git svn rebase
git checkout -b 问题
*在我的所有分支上应用我需要的更改*
*更改*
git commit *更改*
git checkout大师
git合并问题
git svn dcommit

问题在于 svn rebase,甚至提交,我丢失了本地修改但未签入的文件。我不想提交这些文件,因为我不想将它们拉入 svn 提交。

在这种情况下我的工作流程应该如何运作?

Perhaps I'm missing something about using gi through svn, but how do I keep around a set of locally modified files without pushing those changes to subversion.

Here's my broken workflow.

(on master) git svn rebase
git checkout -b issue
*apply changes I need on all my branches*
*changes*
git commit *changes*
git checkout master
git merge issue
git svn dcommit

The problem lies in the fact that svn rebase, or even committing, I lose my locally modified but not checked in files. I don't want to commit the files, because I don't want them pulled into an svn commit.

How is my workflow supposed to work in a situation like this?

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

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

发布评论

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

评论(3

鲜血染红嫁衣 2024-09-19 17:12:48

我的 git-svn 工作流程如下所示:

(on master) git svn rebase
git checkout work
... make commits for all changes, including local-only and those I intend to push up
git checkout master
... cherry-pick changes from work branch
git svn dcommit
git checkout work
git rebase master

最后一个 rebase 步骤将从工作分支中删除已提交到上游的所有提交。

对于 cherry-pick 步骤,我实际上使用了一个小型 shell 脚本,该脚本会自动获取所有提交,除了那些在其描述中包含“NOCOMMIT”的提交。您可以使用其他指示器,例如“LOCAL”或“NOPUSH”或任何您喜欢的指示器。这些提交是那些挂在“工作”分支上并且不会被推送到 Subversion 的提交。

这是我的 pull-work 脚本:

#!/bin/sh

BRANCH=`git branch | grep ^\\* | cut -d' ' -f2`
if [ $BRANCH != "master" ]; then
  echo "$0: Current branch is not master"
  exit 1
fi

git log --pretty=oneline work...master | grep -v -E '(NOCOMMIT|DEBUG):' | cut -d' ' -f1 | tac | xargs -l git cherry-pick

请注意使用 tac 之类的微妙之处,它们颠倒了列出的提交的顺序,以便它们以相同的顺序应用于 master。

My git-svn workflow looks something like this:

(on master) git svn rebase
git checkout work
... make commits for all changes, including local-only and those I intend to push up
git checkout master
... cherry-pick changes from work branch
git svn dcommit
git checkout work
git rebase master

The last rebase step removes all the commits from the work branch that have already been committed upstream.

For the cherry-pick step, I actually use a small shell script that automatically gets all the commits except those that have "NOCOMMIT" in their description. You could use another indicator like "LOCAL" or "NOPUSH" or whatever you like. These commits are those which hang around on the "work" branch and aren't pushed up to Subversion.

Here's my pull-work script:

#!/bin/sh

BRANCH=`git branch | grep ^\\* | cut -d' ' -f2`
if [ $BRANCH != "master" ]; then
  echo "$0: Current branch is not master"
  exit 1
fi

git log --pretty=oneline work...master | grep -v -E '(NOCOMMIT|DEBUG):' | cut -d' ' -f1 | tac | xargs -l git cherry-pick

Note the use of subtleties like tac that reverse the order of the listed commits so they get applied to master in the same order.

寻找一个思念的角度 2024-09-19 17:12:48

听起来好像你的 HEAD 正在被重置。为了避免这种情况,请使用 svn dcommit --no-rebase 。

但是,我认为您的工作流程有些破坏。拥有未提交的文件有点违背了目的,不是吗?

您可能应该使用 git stash。这使得您的新工作流程:

(on master) git svn rebase
git checkout -b issue
*apply changes I need on all my branches*
*changes*
git commit *changes*
git checkout master
git merge issue
git stash
git svn rebase
git svn dcommit
git stash apply

适当地命名您的存储,您应该能够做您想要做的任何事情。

It sounds as though what's happening is that your HEAD is being reset. To avoid this, use svn dcommit --no-rebase.

However, I think your workflow is somewhat broken. Having uncommitted files kind of defeats the purpose, doesn't it?

You should probably use git stash. This makes your new workflow:

(on master) git svn rebase
git checkout -b issue
*apply changes I need on all my branches*
*changes*
git commit *changes*
git checkout master
git merge issue
git stash
git svn rebase
git svn dcommit
git stash apply

Name your stashes appropriately, and you should be able to do whatever it is you're trying to do.

审判长 2024-09-19 17:12:48

如果存储库中不存在该文件,您可以随时将其(或模式)添加到

.git/info/exclude

. Then it would be ignored in git commits and would never end up being pushed into SVN.

If it's a file that doesn't exist in the repo, you could always add it (or a pattern) to

.git/info/exclude

. Then it would be ignored in git commits and would never end up being pushed into SVN.

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