Reputation: 7124
I checked out an earlier version of my project, using:
$ git checkout fd4a4a1
The response was:
Note: checking out 'fd4a4a1'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:
git checkout -b new_branch_name
HEAD is now at fd4a4a1... <original commit message>
I copied a chunk of code, but made no changes. I now want to return to the current branch. However, when I run...
git checkout myCurrentBranch
... git complains:
error: Your local changes to the following files would be overwritten by checkout:
app/.meteor/packages
app/meteo4j.js
Please, commit your changes or stash them before you can switch branches.
Aborting
I don't care about these changes. If they were made, it happened unintentionally. Is it possible to force git to ignore these changes and to checkout my current branch, without changing my history in any way?
Upvotes: 0
Views: 297
Reputation: 239551
Is it possible to force git to ignore these changes and to checkout my current branch, without changing my history in any way?
Yes, use git checkout -f <branchname>
to "force" the checkout to happen, regardless of whether it will clobber any uncommitted changes.
Upvotes: 2