0

I am trying to do a git pull - which is not working because my version and the master version have diverged.

I want to be able to get rid of all the changes I've made on my side and just get the master version as it is.

Here's the git status and git pull details:

C:\Users\User\Documents\Source\Project>git pull

M       Gruntfile.coffee
U       client/site/stylesheets/site.css
U       client/site/stylesheets/site.scss
M       package.json
M       server/app.coffee
M       server/app.js
M       test/main.test.coffee
U       test/main.test.js
D       test/server/GetAndPost.test.js
M       test/server/getAndPost.test.coffee
A       test/server/getAndPost.test.js
A       test/server/testStub.coffee
A       test/server/testStub.test.js

Pull is not possible because you have unmerged files.
Please, fix them up in the work tree, and then use 'git add/rm <file>'
as appropriate to mark resolution, or use 'git commit -a'.

C:\Users\User\Documents\Source\Project>git status
# On branch master
# Your branch and 'origin/master' have diverged,
# and have 1 and 3 different commits each, respectively.
#   (use "git pull" to merge the remote branch into yours)
#
# You have unmerged paths.
#   (fix conflicts and run "git commit")
#
# Changes to be committed:
#
#       modified:   Gruntfile.coffee
#       modified:   package.json
#       modified:   server/app.coffee
#       modified:   server/app.js
#       modified:   test/main.test.coffee
#       modified:   test/server/getAndPost.test.coffee
#       renamed:    test/server/GetAndPost.test.js -> test/server/getAndPost.test.js
#       new file:   test/server/testStub.coffee
#       new file:   test/server/testStub.test.js
#
# Unmerged paths:
#   (use "git add <file>..." to mark resolution)
#
#       both modified:      client/site/stylesheets/site.css
#       both modified:      client/site/stylesheets/site.scss
#       both modified:      test/main.test.js
#
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       modified:   .idea/workspace.xml

C:\Users\User\Documents\Source\Project>git add client\site\stylesheets\*          
fatal: Unable to create 'C:/Users/User/Documents/Source/Project/.git/index.lock':
File exists.

If no other git process is currently running, this probably means a
git process crashed in this repository earlier. Make sure no other git
process is running and remove the file manually to continue.
    #
EternallyCurious
  • 2,345
  • 7
  • 47
  • 78

3 Answers3

0

It is not because you have diverged, it is rather because you have conflicts that need resolution. Edit the files flagged as "both modified" and solve their conflicts then add them.

Generally speaking, you should read what git's output as it often states what need to be done.

fpietka
  • 1,027
  • 1
  • 10
  • 23
  • If I try to add or remove a file, I see the error that I have shown above. See the last command in my question. I get that even when I try to do a git rm on these files. – EternallyCurious Jul 30 '14 at 11:14
  • It seems a process to resolve the merge has been launched already, and maybe crashed as git is suggesting. If you are sure it indeed crashed, remove then file as suggested here and try again. – fpietka Jul 30 '14 at 11:19
  • I have deleted all files on the "unmerged path" from my system. I'm not sure which other files does it want me to remove. I've deleted these because the master has the copy that I want to retain. – EternallyCurious Jul 30 '14 at 11:28
  • It may suit you need here, but git was telling you to delete "C:/Users/Anjan/Documents/Source/Intellisten/.git/index.lock" – fpietka Jul 30 '14 at 11:32
0

Step 1:

Add the files under 'unmerged paths' to 'Changes to be committed' by running the following command

git add client/site/stylesheets/site.css client/site/stylesheets/site.scss test/main.test.js

(run the above command only if you are sure that you have fixed your conflicts).

Step 2:

Then, Commit the files which are under 'Changes to be committed' section by the following command

git commit -am "commit message"

('-am' means, it will commit all the files in a single commit with the message you specify)

Step 3:

Now, do git pull

Hope, this will help you.

Thanks

Breen ho
  • 1,601
  • 14
  • 23
  • I cant add the files to git as you have shown above. I get an error which I have updated the question to reflect. – EternallyCurious Jul 30 '14 at 11:14
  • After I do the git pull, it says "Already up-to-date.". I have removed the unmerged files from my local machine, and I want to get the entire repository as it is. – EternallyCurious Jul 30 '14 at 12:08
  • It seems the git process is already running. Try to kill the git which was already running by the following commands ps aux | grep git , kill -9 and then try proceeding with git commands. – Breen ho Jul 30 '14 at 12:16
  • I am running windows and there is no git process running. I've restarted the terminal and checked the task manager > processes – EternallyCurious Jul 30 '14 at 12:20
  • Try to remove your .git/index.lock file and then try again. For more details read this http://stackoverflow.com/questions/9185053/git-svn-error-a-git-process-crashed-in-the-repository-earlier – Breen ho Jul 30 '14 at 12:26
  • I've already deleted the index.lock file. Despite that I'm getting the "Already up-to-date." message. And I just restarted the my pc too. – EternallyCurious Jul 30 '14 at 12:47
  • What would you do, if you just wanted to get everything from the master copy from github on your desktop? – EternallyCurious Jul 30 '14 at 12:49
  • you mean, to your local branch..? Do you want to sync the contents from your master branch to your local branch..? – Breen ho Jul 30 '14 at 13:28
  • if so, Try the command git fetch origin && git reset --soft origin/master && git clean -f -d – Breen ho Jul 30 '14 at 13:30
  • That cleaned up my project folder. But there are some files in the master that I had deleted in my project - they have not been recreated. – EternallyCurious Jul 30 '14 at 13:37
  • Thanks for accepting my answer. I dint not get your last comment.. Could you please elaborate..? – Breen ho Jul 30 '14 at 15:22
  • I meant to say that there are some files in my project that I had deleted manually on my machine... although they were present on the master. I wanted to download the files from the master - on my machine which I have now been able to do. – EternallyCurious Jul 31 '14 at 03:49
  • Do git status, then it will show you the deleted files, then git checkout deleted_file_1 deleted_file_2 . Then it will be reverted.. – Breen ho Jul 31 '14 at 10:36
0

Note that adding files is the first step.
But the second shouldn't be "git commit -a" (like the git pull return).

Since Git 2.2.0+ (November 2014), you shouldn't see that exact error message anymore.
See commit 91e70e0 from Matthieu Moy (moy):

merge, pull: stop advising 'commit -a' in case of conflict

'git commit -a' is rarely a good way to mark conflicts as resolved:
the user anyway has to go manually through the list of conflicts to do the actual resolution, and it is usually better to use "git add" on each files after doing the resolution.

On the other hand, using 'git commit -a' is potentially dangerous, as it makes it very easy to mistakenly commit conflict markers without noticing, and even worse, the user may have started a merge while having local changes that do not overlap with it in the working tree.

While we're there, synchronize the 'git pull' and 'git merge' messages: the first was ending with '... and make a commit.', but not the latter.

Eventually, git should detect that conflicts have been resolved in the working tree and tailor these messages further.
Not only "use git commit -a" could be resurrected, but "Fix them up in the work tree" should be dropped when it happens.

In your case, a simple git commit -m "fix merge" would be enough.
git commit -a risks to include too many files.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250