Git fetch and merge ONE file only #23783
-
Greetings! Just getting started with git and GitHub. I am mostly working on my local copy (only master branch for now), pushing to origin occasionally. But today I had bunch of local commits (not pushed) and I updated README.md on the GitHub web site resulting in two different versions. I figured out
and
I could see new files added and README with all deletions … I was hoping to do something like
Is this possible? On a related note: At any rate I ended up coping REDAME additions from web, doing
Editing on-line
It worked but it was awkward … Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
radovan-urban:
I’m not sure what you mean by that, could you explain? From your description up to that point I would’ve assumed that
radovan-urban:
That’s exactly what they are. When called on two trees (in this case branches) |
Beta Was this translation helpful? Give feedback.
-
Thank you for a quick reply. The issue I created was that I had changes in BOTH local and origin repos. The local changes were significantly more extensive (new files and other edits to almost all files). The origin edit was impulsive one: updating README file. The task I was trying to achieve: When I did
it showed deletions to all my local files (disastrous) and addition to README (desirable). Question remains: can I update a single file without touching anything else? Thanks you. |
Beta Was this translation helpful? Give feedback.
-
Ah, I think there might be a misunderstanding about A merge would try to bring the changes on both branches since the last common ancestor commit together: Both your new local files, and the README change in the GitHub repository. So yes, it sounds like a A problem that can happen when merging is a merge conflict, e.g. if the same section of a file has been changed on both branches, or a file has been changed on one branch and deleted on the other. In that case git will notify you about the conflict and you’ll have to resolve it manually, deciding what you want to keep. I recommend reading the Basic Branching and Merging chapter of the Git Book to get a better idea of what merging does. |
Beta Was this translation helpful? Give feedback.
Ah, I think there might be a misunderstanding about
git diff
here. A diff does not show you what happens if you would merge, it just shows you the differences between the branches as they currently are.A merge would try to bring the changes on both branches since the last common ancestor commit together: Both your new local files, and the README change in the GitHub repository. So yes, it sounds like a
git merge origin/master
would have gotten you what you wanted. :slight_smile:A problem that can happen when merging is a merge conflict, e.g. if the same section of a file has been changed on both branches, or a file has been changed on one branch and deleted on the other. In that case gi…