Вопрос

I'm struggling to get this to work, most likely because of a lack of understanding of what each command is actually responsible for.

I have:

  • "A", a bare repo
  • "B" cloned from "A" (it should maybe be a branch in "A," instead, but let's start with this use case.) Initially, it was cloned as bare, but when merging, I need to have a working copy.
  • "B" never pushes to "A"

Scenario:

  1. "A" gets whole 9 yards updated including dir 'Z'
  2. "B" had just one dir 'Z' changed

I want to:

  1. pull all changes from remote "A", except 'Z'
  2. keep changes from "B" made in 'Z' over those from "A" in any revision.

I've already tried to accomplish this by doing the following.

in "B":

  1. git fetch -a -t origin
  2. git merge --no-commit --no-ff TAG
  3. git reset Z
  4. git commit

It doesn't work.

  1. git pull --rebase origin master

Still updates 'Z', so I don't know where to reset 'Z'.

Это было полезно?

Решение

Instead of git reset, you'll want to use git checkout in step 3:

  1. git fetch -a -t origin
  2. git merge --no-commit --no-ff TAG
  3. git checkout HEAD -- Z/
  4. git commit

In general, git checkout is the way to say "make something in my working copy look like the reference I describe," whether it's your entire working copy, a file, or a subdirectory. That's exactly what you want here: during the merge, you want to say "scrap any changes that were merged in, and instead make directory Z look exactly like it does in HEAD". (Remember that HEAD hasn't moved yet because the merge hasn't been committed!)

git reset is generally used for manipulating some subset of HEAD, the index (changes that you've staged for commit), and the working copy together to some state. Reset can be confusing, but there's a good, in-depth write-up on git-scm.com if you want more information.

Другие советы

So if i got your question correct you should git checkout -b newbranch on B to get all your changes in a new branch and git commit them.

After committing your changes you can now switch back to master and do git fetch -a origin && git merge origin/master. Above command will merge in all changes from A onto B.

Following the merge you can use git rebase master newbranch to get all your changes on B from before and rebase them onto changes from A.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top