We are having switch configuration files stored with git (not the best idea as it seems now..). The problem now is, that I've updated the switches, commited my changes and now have noticed, that there were upstream changes happening.
Since my local commited configuration is the most recent one, I want to just kind of put my files on top (not just the changes I did), but replace all the potential changes that were done upstream, without losing the upstream history.
Maybe a picture helps here:
before:
*-*-*-* origin/master
\
@ master (local)
after:
*-*-*-*-@ origin/master, master (local)
Normally I'd do a rebase, but this would include all the changes that were done to those files from upstream.
One "solution" would be to remove my commit, copy all the files out, pull and recommit with the replaced files, but this isn't really git'ish (as my problem itself maybe) and I probably have to do that again in the future anyways, so I might as well ask for a better approach.
CodePudding user response:
You use checkout for that
git checkout origin/master
git checkout master -- the-file # set the file the way it is in local master branch
git commit "There you go"
git push origin HEAD:master # set it like this in the remote
git checkout master
git reset --hard origin/master # set local master branch the way it is in origin/master
If we were talking about a whole project (many files, not just one), then you would be better suited using reset --soft
git checkout master
git reset --soft origin/master # set the branch pointer to origin/master content of files do not change
git commit -m "Here I am setting it like local master"
# that commit is done on master.... so no need to hack master... just push to remote
git push origin master