Conflicting file versions (Git)
Naar navigatie springen
Naar zoeken springen
Can't push because behind - Case: 2023.10
On a beautiful autumn morning in 2023, we were greeted by a wonderful message:
$ git push To https://github.com/acme/scripts.git ! [rejected] main -> main (non-fast-forward) error: failed to push some refs to 'https://github.com/scme/scripts.git' hint: Updates were rejected because the tip of your current branch is behind hint: its remote counterpart. Integrate the remote changes (e.g. hint: 'git pull ...') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details.
and git pull
made sure there was no escape:
$ git pull error: Your local changes to the following files would be overwritten by merge: src/update_all_dvb8.sh Please commit your changes or stash them before you merge. Aborting
Options:
- Make a local copy of the site, pull and manually incorporate my updates in this file?
- Check on GitHub for changes
- Commit your changes: Commit, pull, and sort things out manually
- Stash: 'Park' your own changes and proceed with pull
BTW, merge here means, that I want to include my changes in the current branch - To merge my files into the branch
Someone else changed a file as well - Case: 2023.12.04
- Someone else made a change to a file and added one line
- Made a local copy of the disputed file
- Commit + pull
- Git somehow solved it itself. I think the term recursive was mentioned somewhere?
- Solved.
Impressive. Next time, do the same inlcuding making a local copy of the file before pulling.
Someone else changed a file as well - Case: 2024.06
The problem
- I created file
monitoring.sh
- O. changed the file
- I changed the file
- I tried to sync and got
The solution
No idea how this happened, but when I checked some weeks later, both O.'s and my changes, were incorporated in the script.
Someone else changed a file as well - Case: 2024.07.02
This problem was similar the the problem I had a month earlier. It's even concerning the same file as last month.
Problem
$ git pull remote: Enumerating objects: 11, done. remote: Counting objects: 100% (11/11), done. remote: Compressing objects: 100% (8/8), done. remote: Total 8 (delta 4), reused 0 (delta 0), pack-reused 0 Unpacking objects: 100% (8/8), 2.19 KiB | 249.00 KiB/s, done. From https://github.com/example.com/scripts 020ac01..da7a0ae main -> origin/main Updating 020ac01..da7a0ae error: Your local changes to the following files would be overwritten by merge: src/monitoring.sh Please commit your changes or stash them before you merge. Aborting
Cause
O. and I, both changed file monitoring.sh
before I committed my changes.
Additional information
See Git stash for some experimenting with git stash
.
Approach
- O. probably made only one minor and specific change, while I made tens of changes in this file. Hence I would prefer my version of the file to use as basis
- I would prefer to resolve the issue manually. Just like old-school have two versions of the files alongside eachother
- I'm not that versed in Git and I don't want to spend too much time on it. While trying and reversing
git stash
, I made backups of both versions of the files and now can open them side-by-side - When opening these files side-by-side, I discovered that the remote changes were already incorporated in the local file. They seem fine, but I find it worrying that changes are made so easily, and I only find them by compairing the files.
See also
- git stash - This article was written as a result of the 2024.07.02 case