1

I altered some names of files as I started to split up my classes, but now I am getting an conflict error. How do I resolve this?

CONFLICT (rename/rename): Rename "Ruby_game.rb"->"game.rb" in branch "HEAD" rename "Ruby_game.rb"->"ruby_game.rb" in "bb755b75896b09a2113c4a6b2a5a60dcf7d3ea2a" Automatic merge failed; fix conflicts and then commit the result.

Update: I deleted the ruby_game.rb file from the directory on my OS, then I resaved it from Sublime Text under Ruby_game.rb into the directory, then did the git mv Ruby_game.rb ruby_game.rb. Now it wont let me commit due to "unmerged files."

I have read the other linked post but I am at such an rudimentary level that any slight variance throws me off. Note this is my first post here and I am just getting a hang of formatting and protocol, so please if I am not following best practices just considerately nudge me in the correct way.

Phrogz
  • 271,922
  • 98
  • 616
  • 693
  • What is the exact error? – Brennan Jan 22 '15 at 16:32
  • Don't post that as a comment, post it in your question – zero298 Jan 22 '15 at 16:37
  • 1
    sorry like I said I am fresh off the boat using stack :/ –  Jan 22 '15 at 16:38
  • possible duplicate of [How do I commit case-sensitive only filename changes in Git?](http://stackoverflow.com/questions/17683458/how-do-i-commit-case-sensitive-only-filename-changes-in-git) – Michael Berkowski Jan 22 '15 at 16:39
  • Ok I realize it potentially may be a duplicate, and I will delete this off the forum after I get a clear answer to preserve less clutter, but again I am new to git and the programming world. The link says git is not case sensative and I need to use git mv What exactly do I need to do here? I thought git mv was to move files to different directories. –  Jan 22 '15 at 16:41
  • should I just do git mv Ruby_game.rb ruby_game.rb? That doesnt seem to work I get a fatal bad source :( –  Jan 22 '15 at 16:44
  • @Chris 1) Rename it back to the capital letter in your OS; 2) `git mv -f Ruby_game.rb ruby_game.rb`; also, don't worry, you don't have to (and should not) delete this question/answer. If enough people agree that it is a duplicate, it will be _closed_ (preventing new answers) and will point to the duplicate question, but the good and subtly different information here will be preserved in case it helps others. – Phrogz Jan 22 '15 at 16:54
  • I feel so stupid and unworthy of being on here. I am sorry if I am annoying more seasoned people :( Here is what I did and now I am running into another issue: I deleted the ruby_game.rb file from the directory on my OS, then I resaved it from sublime text under Ruby_game.rb into the directory, then did the git mv Ruby_game.rb ruby_game.rb. Now it wont let me commit due to "unmerged files. I have read the other linked post but I am at such an rudimentary level that any slight variance throws me off. –  Jan 22 '15 at 17:01
  • Chris - do not fret, as you originally said (before I just deleted it :) we were all new once. I suggest that instead of comments you edit your question to show what you tried, and what new errors you received (if any). Note that you appear to have missed the `-f` parameter to the `git mv` command. I'm not sure if that's relevant, though. – Phrogz Jan 22 '15 at 17:02
  • git seems so easy when set up correctly, but Im afraid ive created a bit of a knot out of such a simple change. Is there a way for me to revert back to the days where I can just git add git commit git push? Do I need to run a clean sweep before I can upload my commits to github? I promise I will study up on git more later. I have already perused some useful starter links on here. –  Jan 22 '15 at 17:11
  • Chris: 1) Please do not delete the question contents when you edit to add information; your edit made the entire question make no sense to anyone who had not been following along. I re-edited it to add your comment as additional data. 2) You need to include full error details. 3) Per my comment above, note that you do not seem to have used `-f` when performing the `mv`. Does that help? 4) If that does not help, yes, there is a way to reset things. Do you have any changes that you need to commit other than this file rename? (Did you change the contents of the file, too?) – Phrogz Jan 22 '15 at 17:24

2 Answers2

1

When Git says Automatic merge failed; fix conflicts and then commit the result. it means that it took the contents of two versions of the file, put the conflicts next to each other in the file, and wants you to go through that file and make it clean.

I normally do this by hand. If you open the file in Sublime Text you will (hopefully) see one or more sections like this:

<<<<<<< HEAD
(some lines of content)
=======
(other lines of content)
>>>>>>> master

At the simplest (most manual) you need to edit the stuff between <<<<<<< and >>>>>>> to be correct—sometimes just deleting one of them, sometimes merging the code—delete the <<<<<<< and >>>>>>> lines, save the file, re-add it (git add myfile) and then commit.

I hear that typing git mergetool may give you a sexier way to perform this merge. Since you are on OS X (right?) it may give you something user-friendly.

However, failing that, I think what will work is to:

  1. Rename your file (in the OS or Terminal) back to the original name, Ruby_game.rb
  2. Type git reset HEAD Ruby_game.rb and then git checkout -f Ruby_game.rb to abandon any local changes you've made.
  3. Run git mv -f Ruby_game.rb ruby_game.rb
    • Docs for git-mv.
    • The mv command is not just for moving files, but also renaming them. (Renaming and moving are really the same sort of thing, at the OS level.)
  4. Now git commit -m "Renaming file"
Community
  • 1
  • 1
Phrogz
  • 271,922
  • 98
  • 616
  • 693
  • I am certain this is correct, but I get this error now warning: path 'Ruby_game.rb' is unmerged I will try to research it while I wait for a response. Im sorry to cause you so much trouble, but I genuinely appreciate the help. –  Jan 22 '15 at 18:05
  • http://stackoverflow.com/questions/3021161/git-cant-undo-local-changes-error-path-is-unmerged – Phrogz Jan 22 '15 at 18:11
  • I ended up deleting the repo and starting from scratch. It is clear I have a lot to learn about git beyond the basics, but I have only time to devote to ruby right now and then I will move onto version control. –  Jan 22 '15 at 18:16
0

Someone previously renamed the file to game.rb and now you want to name it ruby_game.rb so there's a merge conflict, double check that the file is the name you want and commit that again. That's it.

DiegoSalazar
  • 12,601
  • 2
  • 31
  • 46
  • 1
    hi diego, I dont think this is quite what happened. My initial file was Ruby_game.rb that had multiple classes within it, and then I started separating the classes to player.rb & game.rb. Finally I decided to rename Ruby_game.rb to ruby_game.rb for better syntax. –  Jan 22 '15 at 16:43
  • This is what the error is telling you, There's a conflict: `Rename "Ruby_game.rb"->"game.rb" in branch "HEAD"` and then your rename: `"Ruby_game.rb"->"ruby_game.rb" in "bb755b75896b09a2113c4a6b2a5a60dcf7d3ea2a" ` – DiegoSalazar Jan 22 '15 at 16:47
  • I am sure this is correct, I am just not sure how to implement it. I probably made a dumb error trying to change these file names without git –  Jan 22 '15 at 16:51
  • It's easy just make sure your file is the name you want and just add and commit that. The error is just telling you it doesn't know which name should be the correct one. – DiegoSalazar Jan 22 '15 at 16:51