Original title: git - update all files that have not been changed
Currently I am trying to update all files in a git repository that have not been changed. Lets say for example I have:
test1.py has been modified locally while both files have been modified remotely. Now I tried:
git stash git pull git stash pop
which restored my changes, giving me a warning that I need to merge test1.py
. So far so good. The problem arises when I try to do the same process again (after both files have been again changed remotly). Git now says
unmerged (6b126638f7c63aa648609afa60ab972a2403502b) fatal: git-write-tree: error building trees Cannot save the current index state
which makes me kind of sad. It just want a simple thing: Update all files that I haven't changed. I will take care of merging later.
The stash entry is kept in case you need it again. There's no magic remedy for such merge conflicts. The only option for developers is to edit the file by hand and keep what they want and dispose of what they don't want. Once they merge and save the file, they will have effectively resolved the git stash conflict.
git stash pop pops the top stash off of the stack and merges it with your working environment. Merging a stash can definitely result in conflicts, if there are committed changes that touch the same piece of work.
Think of the git stash pop command as a two-step process. It pulls the most recent stash from history, makes the appropriate changes to files in the local workspace and then deletes that entry from the stash history.
You resolved the conflict in your file (maybe? see footnote), but Git doesn't know whether you're done or not. You have to indicate to git that you've finished resolving that conflict. (Otherwise, if it let you move on and you hadn't actually resolved it, you could find all kinds of ways to shoot yourself in the foot.)
As far as I know, the way to do that is:
git add <file> # stage the resolved version, which marks it as resolved git reset HEAD <file> # unstage the changes, leaving the resolution just in the work tree
It seems like there should be a way to do both at once with update-index
but it's not obvious to me from a quick look. (But then again, for actual merge conflicts, you never want to mark a conflict as resolved without staging the content; it's just for stashes that this arises.)
And as VonC says in his answer, should this happen again, you can easily see what things had merge conflicts when applying the stash using git status
. They'll be listed in red (if you have color on) and say unmerged
(or maybe deleted by us/them
if it was a delete/modify conflict).
Footnote: Looking back at your question, I can't actually tell if you fixed the conflicts or not - you just said "so far so good." The "warning" you saw is really meant as a suggestion to resolve the conflicts immediately. The conflicts arose when trying to combine the changes which you pulled with the changes which you had stashed away. You have to resolve that conflict and get your work tree into a consistent state before you can move on in any way. Deal with it just as you would a merge conflict - look in the file, find the conflict markers, figure out what content to keep! (And then look back above for how to finish up.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With