I have two servers for development and production. In the development server I have a new branch merged with origin. Now I want to go to production and pull the changes. But in production server in branch master I have modified two files which is needed only for this server.
So when I hit:
git pull
I get:
error: Your local changes to the following files would be overwritten by merge:
app/code/local/NextBits/DependentCustomOptionsImage/Block/Adminhtml/Template/Edit/Tab/Options/Option.php
app/design/adminhtml/default/default/layout/dependentcustomoptionsimage.xml
Please, commit your changes or stash them before you can merge
These are the two files I need.
How can I pull the origin and without overwriting these files?
Or how can I keep these files, pull the changes and revert them back?
There are at least three different solutions to achieve this:
You can commit
your changes on these two files in the production server, before running git pull
:
git add -v -u
git commit -m "Save prod config"
git pull
This will typically create a merge commit combining the local branch (with the commit "Save prod config"
) and the changes from your remote.
If there is some conflict, you'll just need to resolve it with the help of git status
, git diff
, and git commit
.
For subsequent updates, it should suffice to run git pull
.
Like the previous solution, you can commit
your changes on the two production config files, but run git pull -r
afterwards:
git add -v -u
git commit -m "Save prod config"
git pull -r
The -r
option stands for --rebase
and means that the local commit(s) specific to the production server will be rebased on top of the pulled commits.
Subsequent updates can be performed by running git pull -r
.
The main advantage of this solution is just the ability to keep a "linear history": there is no merge commit created and the "Save prod config"
commit will always be replayed at the 'end' of the history.
or you can use the git stash
command (which may have some drawbacks in case of conflict):
git stash
git pull
git stash pop