1

From the below code (source: Merge two Git repositories without breaking file history), I have trouble visualizing where exactly old_a/master and old_b/master point to at each step along the process.

# Assume the current directory is where we want the new repository to be created
# Create the new repository
git init

# Before we do a merge, we have to have an initial commit, so we'll make a dummy commit
dir > deleteme.txt
git add .
git commit -m "Initial dummy commit"

# Add a remote for and fetch the old repo
git remote add -f old_a <OldA repo URL>

# Merge the files from old_a/master into new/master
git merge old_a/master

# Clean up our dummy file because we don't need it any more
git rm .\deleteme.txt
git commit -m "Clean up initial file"

# Move the old_a repo files and folders into a subdirectory so they don't collide with the other repo coming later
mkdir old_a
dir -exclude old_a | %{git mv $_.Name old_a}

# Commit the move
git commit -m "Move old_a files into subdir"

# Do the same thing for old_b
git remote add -f old_b <OldB repo URL>
git merge old_b/master
mkdir old_b
dir –exclude old_a,old_b | %{git mv $_.Name old_b}
git commit -m "Move old_b files into subdir"

My questions: 1) Could someone draw (diagrams w/pointers) what happens to all the existing pointers at each step in the process? 2) What happens if you git push old_a master or git push old_b master after the steps above? (Do the repositories receive the entire new folder with both old_a + old_b stuff and why?)

Appreciate any insight!

Community
  • 1
  • 1
fibono
  • 773
  • 2
  • 10
  • 23

2 Answers2

0

I won't draw a diagram, but gitk (or git log --oneline --graph --decorate if you prefer text-mode) can do that for you. By default, they show the history reachable from HEAD, add --all if you want to see all branches at the same time, or run gitk old_a/master old_b/master to view just the history of the two remote-tracking references you're interested in.

Matthieu Moy
  • 15,151
  • 5
  • 38
  • 65
0

1) I don't gonna draw for you. Use gitk -a to draw your history yourself. 2) I'm not sure if your dir|%{} commands are right, as I don't use windows cmds, but yes, if you push to old_a a/o old_b they will have the same layout as your local repository, that is

./old_a/AFILES
./old_b/BFILES

because git doesn't even care about files. Internally git just works with the contents, but you told git to mv all old_a files into a new directory ./old_a and same for old_b.

Actually git mv is a shell mv plus git rm oldpath and git add newpath. these rm/add combinations will go to old_a and old_b when you push that commit.

ikrabbe
  • 1,909
  • 12
  • 25