2

I have not been able to find a similar answer to my question.

Situation:

Locally using GIT (git version 1.7.3.1.msysgit.0)
Remote repository is SVN (not sure of version)


Problem:

Clone an SVN repo, add a folder, commit it to git and SVN, rename the folder (without telling git), commit to git, cannot commit anymore to SVN.


Issue Steps (SVN repo has one file in it main.as in the root folder)

  1. clone branch from SVN repo (now have one file locally)
  2. commit to git locally (including git add .)
  3. create oldFolder with a file in it
  4. commit to git locally (including git add .)
  5. dcommit to SVN
  6. rename oldFolder -> newFolder (rename with IDE or manually - not git-mv)
  7. commit to git locally (including git-add .)
  8. dcommit to SVN (don't need SVN rebase since I'm the only one committing changes to SVN)

PROBLEM: The git-svn dcommit responds:

oldFolder/file.txt: needs update

update-index --refresh: command returned error: 1

What I tried:

  • stash, commit, dcommit, stash apply (same thing:needs update)
  • stash, rebase, stash apply, commit, dcommit (same thing:needs update)
  • stash, rebase, stash apply, commit, stash, dcommit (same thing:needs update)

The one that semi-worked was to call:

svn rm -r oldFolder

but this ended up with oldFolder and newFolder in SVN... whereas I want oldFolder to be either renamed or deleted (I don't mind losing the history in this case).

I need the SVN repo to reflect my local git master/branch...


Why am I renaming files without the git command?
I work with large file structures and the IDEs that im using for refactoring old code renames multiple folders and files causing the above scenario. I cannot keep track and call git rm on every folder removed.

Jason Plank
  • 2,336
  • 5
  • 31
  • 40
mihai
  • 4,184
  • 3
  • 26
  • 27
  • Are you sure you don't need to do a `git svn rebase` first? Looks like there are svn changes which you don't have yet. – Mike Weller Oct 12 '11 at 16:27
  • thank you for the suggestion. git svn rebase will result in the same issue. Also I'm the only person currently dcommitting to svn right now. – mihai Oct 13 '11 at 15:44

2 Answers2

2

At step 7, you staged the addition of the new file (newFolder/file.txt) but not the deletion of the old file. You'll need to do the following instead of step 6 and 7 above:

  1. rename oldFolder -> newFolder (rename with IDE or manually - not git-mv)
  2. git add newFolder
  3. git rm -r oldFolder
  4. commit locally

At this point, git will track renames (if any), and produce a correct commit for SVN.

If your tree is still at step 7, you can do

git reset --soft HEAD~

to return to the previous commit and stage the deletion.

Devin Lane
  • 964
  • 1
  • 7
  • 14
  • @Devin... thank you for the reply and yes this would have worked but sadly not for my situation. I work with a large number of files and in the case where I refactor a large number of folders (sometimes with one command) it will be a headache to call add/rm on all the newFolders and oldFolders. I was hoping there was a way for git to know which files were added (git add -A) and which were removed without having to explicitly name each one. – mihai Dec 02 '11 at 16:44
  • @mihai Git does know which have been deleted, but you have to stage them to commit the deletion. Otherwise it's just changes in your working tree. It seems you might want the "git add -u" option which will stage all changes to tracked files including removals, but ignore untracked files. – Devin Lane Dec 03 '11 at 02:55
  • thank you. the explanation is very clear and I will give that a shot. – mihai Dec 05 '11 at 16:07
0

(Adding another answer just for the sake of completeness)

A git add --all adds all modifications, including deletes and renames.

So the following sequence of commands usually "just works", even in the case of folder renames:

git add --all
git commit -m "some msg"
git svn dcommit

We don't really need to git rm -r OLD_FOLDER (unless, of course, when we want to fine-tune the Git index definition).

rsenna
  • 11,775
  • 1
  • 54
  • 60