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?

0

4 Answers 4

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

Sign up to request clarification or add additional context in comments.

Comments

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 

Comments

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.

Comments

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 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.