Search code examples
gitgithubgit-mergegit-diff

Beginner Git merge confuse about two branches


I am new to Git, and I'm confused.

Here's an example:

  • I build a repo called prj in my office.
  • I add an image to it and commit to GitHub
  • Later, when I back home, I clone this repo, check out a new branch (let's call it home) and replace this image with another one with same name.
  • Then, after I go back office, I delete the old image, and update the remote branch. Everything seems to work at that stage.
  • I use git diff master origin/home, which shows a new node added for that image. However, when I run git merge origin/home, the image I added at home can not be added to my local master.

Where did I do wrong? How can I do something just like SVN update?


Solution

  • On your office computer - don't delete the image. Reset your local changes to the image file, then do the pull. You should see it's content update.

    If you still don't see it update, delete the old image, commit the deletion, then try adding the new image again. Sometimes git is weird about replacing files that have the same name.