Sean’s Obsessions

Sean Walberg’s blog

Svn Merge

(this is one of those “so I remember it” posts that might help others)
Edit: See below for a more accurate way to merge the trunk back into HEAD

I’ve got some code that I’m storing in SVN. In traditional SVN form, I’ve got my repo set up as

/trunk
/branches

So my work is done out of trunk, ie

1
svn co http://home.ertw.com/svn/repos/payroll/trunk/ payroll

I then had some major rework I wanted to do. Rather than continuing to develop out of trunk, I wanted to keep these changes separate so that I could continue working on other things in the code base at the same time as the rework. In svn, that’s done as a branch. From the root of the checked out code:

1
2
svn copy http://home.ertw.com/svn/repos/payroll/trunk http://home.ertw.com/svn/repos/payroll/branches/engine_mark_2
svn switch http://home.ertw.com/svn/repos/payroll/branches/engine_mark_2

The first command copies all the files from the trunk to a branch called “branches/engine_mark_2”. Note that the “trunk” and “branches” are just directories, they have no meaning themselves. I could develop out of /, or even out of /fred and branch to /wilma.

The second command switches the current repository from /trunk to /branches/engine_mark_2. I had just checked in all the code, so nothing had to change, it was just a pointer to where I was storing changes.

So, I could continue working on this branch, and also check out /trunk to somewhere else to make changes.

After all the work in the branch is done and checked in, take a look at the current branch:

1
2
3
4
5
6
7
8
9
10
11
[sean@sergeant payroll]$ svn info
Path: .
URL: http://home.ertw.com/svn/repos/payroll/branches/engine_mark_2
Repository Root: http://home.ertw.com/svn/repos/payroll
Repository UUID: 116013b7-0df0-436d-95c2-deac7dca3705
Revision: 92
Node Kind: directory
Schedule: normal
Last Changed Author: sean
Last Changed Rev: 92
Last Changed Date: 2009-08-24 20:57:22 -0500 (Mon, 24 Aug 2009)

The revision the branch started at is 92.

I checked out a copy of /trunk to another directory:

1
svn co http://home.ertw.com/svn/repos/payroll/trunk payrolltrunk; cd payrolltrunk

Then merge version 92 to the head, giving the url to the branch:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
svn merge -r 92:HEAD http://home.ertw.com/svn/repos/payroll/branches/engine_mark_2
--- Merging r93 through r95 into '.':
U    test/unit/accrual_test.rb
U    test/unit/employer_test.rb
U    test/factories.rb
U    test/lib/tax_calc_test.rb
U    test/lib/cpp_ei_test.rb
--- Merging r93 through r95 into 'test/lib/finalize_test.rb':
U    test/lib/finalize_test.rb
--- Merging r93 through r95 into '.':
U    test/lib/pre_flight_test.rb
A    test/lib/payroll_procedure_test.rb
U    app/models/employee.rb
U    app/models/accrual.rb
U    app/models/employer.rb
U    app/controllers/payroll_controller.rb
U    db/schema.rb
A    db/migrate/20090827031532_add_payroll_run_to_accrual.rb
A    db/migrate/20090827032200_add_status_to_employee.rb
U    lib/payroll_engine.rb

At this point you’re sitting in a copy of HEAD with the branches changes merged it. Thankfully I had no conflicts, otherwise I’d have to resolve those before continuing by looking at the files with a status of “C” and fixing the conflicts that are marked by SVN inside the file.

Finally, commit the changes to HEAD:

1
svn commit

Then, either wipe out all your checked out copies and check out HEAD again, or switch your working copy of the branch back to head:

1
 svn switch http://home.ertw.com/svn/repos/payroll/trunk

The branch can stay as is.

Edit
After doing this again I found a problem trying this again when I had added files to the repository in the branch, and was getting “Skipped missing target” errors.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
svn log --verbose --stop-on-copy $BRANCH
...
------------------------------------------------------------------------
r106 | sean | 2009-09-04 07:56:23 -0500 (Fri, 04 Sep 2009) | 2 lines
Changed paths:
   A /branches/reporting (from /trunk:105)
Branching to integrate reports
# now in a checked out version of trunk
[sean@sergeant payroll]$ svn merge -r 106:HEAD $BRANCH
--- Merging r107 through r117 into '.':
A    test/unit/helpers/payroll_history_helper_test.rb
U    test/unit/accrual_test.rb
U    test/functional/payroll_controller_test.rb
A    test/functional/payroll_history_controller_test.rb
A    app/helpers/payroll_history_helper.rb
U    app/models/employee.rb
U    app/models/payroll_run.rb
U    app/models/accrual.rb
U    app/models/employer.rb
U    app/controllers/payroll_controller.rb
A    app/controllers/payroll_history_controller.rb
U    app/views/layouts/application.html.erb
U    app/views/payroll/run_final.html.erb
A    app/views/payroll_history
A    app/views/payroll_history/index.html.erb
A    app/views/payroll_history/get.html.erb
A    app/reports
A    app/reports/pay_stub_aggregator.rb
A    app/reports/pay_stub_controller.rb
U    config/environment.rb
U    db/schema.rb
U    lib/payroll_engine.rb

Second edit

So I was working in a branch (copied at revision 147) and had made some updates to HEAD that I wanted to sync up.

From my working copy of the branch:

1
2
3
$ svn merge --dry-run -r 147:149 http://home.ertw.com/svn/repos/payroll/trunk .
U    test/lib/cpp_ei_test.rb
U    lib/payroll_engine.rb

The –dry-run tells me which files will be updated. That was good, so I re-ran without the –dry-run.

Comments

I’m trying something new here. Talk to me on Twitter with the button above, please.