0

I can not get my head around the sequence to merge this mess. Whatever I try I get stuck, or in too deep to go further for fear of breaking things.

  • User A is working on repo no probs.
  • Unknowingly user B gets a Zip of repo, does not init locally and makes code changes locally.
  • User A learns of this, and commits all his pending changes.

So, how to merge changes from both A and B while keeping the repo intact? Initially I have a copy of both local folders (one with a .git from A and one without a .git from B).

Amit Verma
  • 40,709
  • 21
  • 93
  • 115
Tuco
  • 51
  • 5
  • This sounds like a lousy workflow (everyone should be using git). But can't you commit user A's changes, then copy user B's non-git copy over user A's folder, and then commit those changes too? – Aaron Brager Jul 09 '14 at 18:20
  • Agreed, but stuff happens, especially when User A was told that B starts today but he got a copy a week ago and started making changes and has never used HG. Yes, A's interim changes were committed. Copying B's files over A's will no doubt cause a subsequent push reject, not? – Tuco Jul 09 '14 at 20:00
  • 1
    No, if you copy user B's stuff over user A's (after user A commits), it will be as if user A made the changes that user B did. Just copy over, then commit again. (Assuming they didn't change the same code areas, in which case you'll have to do manually decide which version you want to keep; this is analogous to a merge conflict.) – Aaron Brager Jul 09 '14 at 20:24
  • And, specifically, look at the changes and decide what to stage for commit and what not to stage for commit, before actually committing. – Aaron Brager Jul 09 '14 at 20:25
  • @AaronBrager thanks for the pointers. Even after ignoring all the unexpected [file mode diffs](http://stackoverflow.com/a/14794405/1879777) there were too many conflicts to manage vs. just copy B over A, commit, then redo A's changes. We should be rolling again when B deletes local repo and clones properly. – Tuco Jul 10 '14 at 13:25

1 Answers1

0

A bit late, but for future readers, here's how I'd solve this problem without many conflicts to be resolved:

git clone thecorrectrepositoryurl xxx
cd xxx
git checkout to-a-commit-where-mistaken-developer #was at before committing the mistakes, or branch

Now copy over all files from the mistaken developer. And if there is chance for deleted files, remove all files before copying the files

With no conflicts, adding deleted files, commit and checkout the current branch

git commit -A -m "Changes that should have been in git already"
git checkout the-current-branch

Git will tell you about losing changes if you checked out a commit, otherwise replace the below with:: git merge [your-branch]

git merge abcf00 # Add the refspec git mentioned, example abcf00 

Resolve the conflicts, there should not be many

git commit -m "Merge Changes that should have been in git already"
twicejr
  • 1,319
  • 3
  • 13
  • 21