-1

I want to merge in a branch in which a directory has been moved, and I have added files in this directory in my branch. However, when I tried to do this, the new files in my branch were not moved to the new directory.

I am not sure whether this is relevant, but an additional complication in this repository is that the "new" directory used to exist as well, and the other branch simultaneously deleted the old version of the new directory and moved the old directory over the top of it. The presence of the old version of the new directory was due to a misuse of directories in our repository for versioning purposes, which should really have been handled by git instead, but it was a convenient thing to do at the time.

So, how can I, while doing an "interactive merge" (i.e. solving a merge conflict or using git merge --no-commit), find all the files that are new and move them to the new directory?

The problem is, that while in this "merging state":

  1. The files to be deleted during the merge, are not actually deleted yet. I don't want to move them over to the new directory, because I am worried that they are possibly outdated versions of those files.
  2. There are also some ignored files in the old directory. I don't want to move them over either.
  3. git status doesn't show the new files as added, because they are not - they were already committed to the current branch.
  4. The files in question actually exist in the working tree in both the new and the old directory, although they don't seem to be registered with git in the new directory (a possible git bug? I am confused about what is happening here)
Robin Green
  • 32,079
  • 16
  • 104
  • 187

1 Answers1

0

Point 2 should not really be necessary to avoid for most ignored files, but there are some types of files that don't work properly when moved in certain ways, so if you really want to delete them you can do git clean -i -x -d <old directory>.

For point 1, you can action the deletes by doing git checkout -- <old directory>.

Point 3 is now unimportant because we now have all the files we want to move - and only those files - existing in the old directory.

Now all that remains is to move them. This is slightly tricky because the new directory is not empty, but you can use this answer for that on Linux and Mac OS X. Unfortunately that script does not register the moves with git, so you will probably want to change the mv commands to git mv -f in that script (-f must be supplied in this case, due to point 4).

Community
  • 1
  • 1
Robin Green
  • 32,079
  • 16
  • 104
  • 187