- What I’m trying to do:
I work with two friends on a university project, they made some changes to the code.
I’ve also made a lot of changes to the code, most of which I want to keep.
I’m new to git and don’t know where to start.
My friend suggested I use:
git pull origin
When I do that I get:
error: Your local changes to the following files would be overwritten by merge:
Please, commit your changes or stash them before you can merge
I read somewhere on stackoverflow: How do you git fetch then merge? "Error: Your local changes to the following files would be overwritten by merge"
That if I don’t commit changes to local repository, they’ll be lost?
- How do you commit locally?
- How do I merge changes(Is there a way I could use beyond compare please)?
- How do I upload the changes?
Thanks
This is what it looks like now:
Arthur Wulf@SUPERWOLF-PC /c/Current Project/study-wise (master|MERGING)
$ git pull origin master
M .pydevproject
U src/app.yaml
M src/getters/__init__.pyc
M src/index.yaml
M src/model/ClassM.pyc
M src/model/CourseM.py
M src/model/CourseM.pyc
M src/model/GeneralM.pyc
M src/model/LectureM.py
M src/model/LectureM.pyc
M src/model/PostClassM.py
A src/model/PostClassM.pyc
M src/model/QuestionM.py
M src/model/QuestionM.pyc
M src/model/StudentM.py
M src/model/StudentM.pyc
M src/model/TopicM.py
M src/model/TopicM.pyc
M src/model/__init__.pyc
M src/setters/__init__.pyc
A src/setters/setQuestionStats.py
D src/setters/setRemoveOldData.py
A src/setters/setStartNewClass.py
A src/setters/setStudentAnswer.py
D src/setters/setTopicChanged.py
A src/setters/setUpdateTopicStats.py
M src/view/allCourses.html
M src/view/lecture.html
U src/view/prof.html
M src/view/question.html
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'.
What I do not understand is how do I beyond compare the files on my local side with the ones on the online origin repository side and merge them?
The right thing to do is to commit all your changes locally, and then try pulling again. That error is there to protect you from losing local changes that haven’t been committed. Creating a commit (committing) is like creating a new snapshot of your code, after which that state is safely recorded.
To answer your questions:
Look at the output of
git status. If there are any files listed as “Untracked files” that you want to keep in git, usegit add <filename>...to indicate that you want them in the next commit. Then look at the files listed as “Changes not staged for commit” – these are files that were already in the repository that you’ve changed. You can again dogit add <filename>...for each of those to indicate that you want exactly that version of that file in the commit that you’re preparing. (If you make a further modification to a file, you would have togit addthat file again to stage the new contents of the file for the commit.)Finally, you should run
git commit. That will open up an editor where you should enter a helpful commit message – when you save that file and exit the editor, your commit should be created. Then you can rungit pull origin master, as you originally wanted to.(As a shortcut, if you do
git commit -a, all the changes to files that were already in the repository will be staged for the commit without you having togit addthem.)The
git pull origin mastercommand that you tried actually does two things:masterfrom the remote repository calledorigingit is good at avoiding complaining about spurious conflicts, but if you do need help dealing with them, look into
git mergetool.You can do that with
git push origin master.