2

I want to checkout a branch and I got this message

error: Your local changes to the following files would be overwritten by checkout:  
    src/main/webapp/data/GuerrillaLabels.json
Please, commit your changes or stash them before you can switch branches.
Aborting

But I want those files to be overwritten

carles xuriguera
  • 930
  • 1
  • 14
  • 30
  • 2
    https://git-scm.com/docs/git-checkout#git-checkout--f – axiac Nov 13 '18 at 09:20
  • 1
    Hello and welcome to StackOverflow. Please take some time to read the help page, especially the sections named ["What topics can I ask about here?"](http://stackoverflow.com/help/on-topic) and ["What types of questions should I avoid asking?"](http://stackoverflow.com/help/dont-ask). And more importantly, please read [the Stack Overflow question checklist](http://meta.stackexchange.com/q/156810/204922). You might also want to learn about [Minimal, Complete, and Verifiable Examples](http://stackoverflow.com/help/mcve). – Clijsters Nov 13 '18 at 09:21
  • 1
    Please first search your self in older questions and answer than post your question. – IftekharDani Nov 13 '18 at 09:26
  • 1
    Hi Carles, there are a number of other questions related to this topic, each with answers that should be able to help you. – Edward Thomson Nov 13 '18 at 11:24

1 Answers1

10

git checkout

https://git-scm.com/docs/git-checkout#git-checkout---force

You can pass the -f (force) flag to forcefully checkout the branch, this will wipe out any changes you've made that haven't been committed.

git checkout -f branch

If you don't want to lose all your changes, you can checkout the file specifically with:

git checkout -- src/main/webapp/data/GuerrillaLabels.json

git stash

https://git-scm.com/book/en/v1/Git-Tools-Stashing

You could also stash the changes that you've made and reapply them later on with

git stash

You can view your stashes with

git stash list

And you can apply those stashes by using pop. Passing nothing to pop would apply the last stashed item.

git stash pop

Note: this approach can cause conflicts with code.

steadweb
  • 15,364
  • 3
  • 33
  • 47