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

Updated:   |  Git (Version Control) articles

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

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

 

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 currently selected branch, the git checkout command with the -f or --force flag can be used.

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 6c4408 in the box below so that we can be sure you are a human.