0

Yesterday, my Git server was down and I needed to do some urgent updates to my production system which usually runs 'sudo git pull' from my Git server to fetch the latest changes.

Now that my Git server is up and running again, I've committed a modified version of the changes to Git and would like to pull them on my production server, however, its telling me:

error: Your local changes to the following files would be overwritten by merge:
    config.php
Please commit your changes or stash them before you merge

I want to overwrite the file on my production server with the latest commit from the master branch. How can I do that from my production server?

halfer
  • 19,824
  • 17
  • 99
  • 186
David
  • 16,246
  • 34
  • 103
  • 162

4 Answers4

0

use

git checkout .

to discard any unstaged / uncommited modification in the worktree.

This cannot be canceled, be cautious about what you're doing.


Alternatively you can use

git stash

In case you've discarded important modifications, you can put them back with

git stash pop

or see them with

git stash show
blue112
  • 52,634
  • 3
  • 45
  • 54
0

You can use:

git checkout -f master

This will force git to overwrite local changes and check out the latest commit in master, see the documentation here.

T A
  • 1,677
  • 4
  • 21
  • 29
0

If you no longer need changes in the production server, there are 2 methods.

Method 1: Preferred

git checkout . && git pull

Method 2: Not the best, but gets the job done

git reset --hard && git pull

If you want to keep the changes in the production server for future reference:

git stash && git pull

If you have added new files/folders as a part of the changes in production, then you might want to run a git clean before using any of the above methods.

git clean -df

d - remove untracked directories also

f - force remove all untracked files

halfer
  • 19,824
  • 17
  • 99
  • 186
Sarath S Menon
  • 2,168
  • 1
  • 16
  • 21
0

Since you are saying it is in production, I would recommend you to stash the changes, rather doing the checkout.

Stash helps in saving the changes aside and you will be able to get it back again. I always prefer to stash with a name (helps as a description).

git stash save "<description>"

Applying the stash:

git stash apply stash@{0}

It's better to use apply because the stash will not be deleted.

Listing the stash:

git stash list
torek
  • 448,244
  • 59
  • 642
  • 775
Thiru
  • 2,541
  • 4
  • 25
  • 39