Same user 2 computers, changes lost instead of merged #22917
-
I am pushing to github from the same Windows Domain and same github account but two different computers (I have a laptop-with-vpn at home, and a Desktop at work). I seem to be losing my changes. Git seems to think that each submission of the file is a request to overwrite it with a new edition (instead of merging the home-submission’s changes with those of the work-submission). So if I add 5 lines at work. Then I go home and add 2 lines at home. I should have 7 new lines. Instead I end up with 2 new lines. I’ve lost all my at-work changes. Suggestions anyone please? The commands I use are: git commit -a -m “today’s changes” git fetch origin master git merge origin/master git push origin master |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
I think I can solve this by having a 2nd github account included in the project as a collaborator. If anyone knows a cleaner way to resolve this, please let me know. |
Beta Was this translation helpful? Give feedback.
-
To test this I:
This resulted in the following error message:
And returned exit code 1, signaling an error. If you execute
And the way Git is configured by default, executing
And again, exits with error code 1. Git does all of this specifically to prevent you from losing data. The only way that you could get Git to behave like you’re describing is if instead of The proper thing to do when you see that merge conflict is to resolve the conflict. You’ll notice that the contents of the file at this point are:
If you want all seven lines, then you could edit the file to look like this:
Then:
Which succeeds, as can be seen in the history of the |
Beta Was this translation helpful? Give feedback.
-
Also, to show that if there are no merge conflicts that things wouldn’t behave the way you’re describing, I created another test with
This time I didn’t get an error, I got the following message:
Notice the text “Merge made by the ‘recursive’ strategy.”, confirming that the merge was automatically resolved. Also, there was no error code returned. I then was able to execute |
Beta Was this translation helpful? Give feedback.
To test this I:
janthonyl.txt
as a blank file using the GitHub web UIgit pull
on my local machine with themaster
branch checked out to put both the GitHub repository and my local repository in the same statejanthonyl.txt
file using the GitHub web UIjanthonyl.txt
using my favorite editorgit commit -a -m "Today's changes"
locally to commit the local changesgit fetch origin master
locally to get the changes from the GitHub repositorygit merge origin/master
locallyThis resulted in the following error message: