Reputation: 827
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
Reputation: 77093
I see that this is already answered, but I think a couple of tips might be useful in your case.
.gitignore
. In your git repo root folder, create a file .gitignore
if it doesn't already exist, and add the *.exe
expression there.*.exe
files, use git rm -r --cached '*.exe'
*.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
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
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
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.
$ git stash
$ git pull origin master
$ git stash pop
make your changes
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