Adrien Neveu
Adrien Neveu

Reputation: 827

Git merge conflicted files when pull

Here my situation: We're 2 people working on a C project and we use bitbucket and git as DVCS. We're really new to these systems and don't really know how to use it well.

When we're both working on it, if user A commits the changes, and user B wants to pull its modifications, here's what he get (btw. user B already is also working with some different files):

$ git pull origin master

error: Your local changes to the following files would be overwritten by merge:

I don't care to overwrite the two first files as they are always different when we compile, and I don't care to replace it, but the third one could be great if we could merge it.

We've been searching on the internet and only found that user B should reset its repo.. which is quite stupid as he has modified files on it he'll lost.

So what's the solution to merge all these files?

Thank you!

Upvotes: 0

Views: 329

Answers (4)

Anshul Goyal
Anshul Goyal

Reputation: 77093

I see that this is already answered, but I think a couple of tips might be useful in your case.

  1. Don't include the *.exe in your git repo. There is no point in tracking them, they might change if one of you folks has a different compiler version.
  2. Add the *.exe files to .gitignore. In your git repo root folder, create a file .gitignore if it doesn't already exist, and add the *.exe expression there.
  3. To remove the already added *.exe files, use git rm -r --cached '*.exe'
  4. You should similarly add an expression *.o for any C compiled output files, and another one for *.pdb.

As for ignoring the local changes, @uDay's answer pretty much sums it up - you need to do a git stash, then do a git pull origin master. and then a git stash pop.

The last git stash pop statement has a caveat attached though, you will need to explicitly drop the stashed entry in case of merge conflicts.

Upvotes: 0

tamas.levi
tamas.levi

Reputation: 11

Another solution, a quicker one, but less elegant than stashing would be for user B to commit his local changes to be able to pull the changes from the remote.

git add -A
git commit -m "Commit before pull"

After that user B can pull without problems

Upvotes: 0

Lazureus
Lazureus

Reputation: 461

My solution would be to :

git checkout bin/App.exe
git checkout bin/App.pdb

Above two commands will reset changes in those files, then I would :

git stash 

This command is going to stash my changes temporarily, then I can do :

git pull origin master 

Pull is suppose to go without any merge conflicts,if previous commits from user B won't do any conflicts, then you can come back with stashed changes by command :

git stash pop 

If merge conflicts occur you must resolve them.

Upvotes: 0

uday
uday

Reputation: 8730

You have to do something like $ git stash to stash your changes and then pull the changes from the remote repository and then to overlap your changes you have to do $ git stash pop. Doing this you will have all the changes that B has already commited and once you pop your changes on top of it, you will have your copy and you will be safe to commit and push your changes to the remote.

  1. $ git stash
  2. $ git pull origin master
  3. $ git stash pop

  4. make your changes

  5. Stage them,commit them and push them

If you dont want to pull the changes you can always do a fetch first and then merge only the files you intend to.

I have answered similar question on pull and fetch, merge here hope it helps: https://stackoverflow.com/a/19296457/981616

Upvotes: 1

Related Questions