0

I'm a new user to git, but I've used tHg before, and I'm familiar with the basic stuff of branching and merging. (say, up to using diff tool and resolving conflicts with it) I'm using tortoiseGit to do my work for me, so I can have windows explorer/shell integration. I lack a piece of knowledge on merging using tGit/git. (or better said: I've never try to do anything like this with any SCM before)

I have started a repository from an existing code base. With my new git repo, I've branched off a dev and a test branch. The old code base I started my repo with already included some tests.

Now I'd like to version those tests so I can roll back stuff in the test branch if a test proves to be wrong or something. I think just ignoring them won't be the solution, unless there's a way to still version them in the test branch. I would like to delete my tests from the dev branch so I have a (much) cleaner project file structure in the dev branch, but keep them in the test branch. So, if I delete the tests, the deletion should propagate from the dev branch to the test branch when I update the code to test, right? That's what I don't want to happen. Is there a way to not propagate the deletions?

So, is it possible to push only a selected set of file changes back from dev to test and vice versa? If so, how do I do that?

4

1 回答 1

1

当然:在测试分支上-s ours合并 dev-branch 提交,删除所有测试。但在我看来,您希望完全独立于源代码对测试进行版本控制。你可以把所有子模块都放在上面,但对于这样的事情,只需将它们放在完全独立的分支中,然后合并到“测试”分支中:

T---o---o-------o        tests (contains tests/*)
         \       \
          1---2---3      testing
         /   /   /
D---o---o---o---o        dev   (contains all but tests/*)

要启动测试分支,

git checkout --orphan tests
ls|grep -v tests|xargs git rm -r
git commit -m"just the tests"

做你的测试

git checkout testing  (#git checkout -B testing the first time)
git merge dev tests
# test test fix fix commit commit

然后如果测试确实产生了修复修复提交部分,则有选择地合并回来:

# selective merges from testing
git checkout tests
git merge -s ours --no-commit testing
git checkout --theirs tests    # or however else you want to select fixes
git commit

git checkout dev
git merge -s ours --no-commit testing
git checkout --theirs path/to/fixed/this and/so/on   # likewise
# or git checkout --theirs .; git rm -rf tests
git commit

或者你可以做两步合并:

# selective merges from testing

git checkout -B from-testing testing
# rm everything but tests/*
git add -A; git commit
git checkout tests
git merge from-testing

git checkout -B from-testing testing
# rm tests/*
git add -A; git commit
git checkout dev
git merge from-testing

随着您对这种东西越来越熟悉,您将能够通过重置而不是检查来避免不必要的工作树操作,这是值得的大型项目学习。

于 2013-10-16T15:45:50.923 回答