Bootstrap FreeKB - Git (Version Control) - Resolve "your local changes would be overwritten by merge"
Git (Version Control) - Resolve "your local changes would be overwritten by merge"

Updated:   |  Git (Version Control) articles

Let's say the following error is returned after issuing the git pull command.

error: Your local changes to the following files would be overwritten by merge:
        example.txt
Please, commit your changes or stash them before you can merge.
Aborting

 

The git diff command can be used to show the are differences between the file in the currently selected branch of the cloned repository and the origin Git repository. In this example, the output shows that "Hello World" was added to example.txt in the currently selected branch of the cloned repository.

~]# git diff example.txt
diff --git a/example.txt b/example.txt
index bcd9498..8932028 100755
--- a/example.txt
+++ b/example.txt
+ Hello World

 

If you do not need to keep the changes to the file in your branch, the git checkout command can be used to download the file from the origin Git repository.

git checkout example.txt

 

You might need to use the -f or --force flag.

git checkout --force example.txt

 

If you need to keep the changes to the file in your branch, use the git commit command to commit the change to the file, and to then use the git push command to upload the file to the origin Git repository.

git commit -m "your commit message" example.txt

 

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 5e7b65 in the box below so that we can be sure you are a human.