0

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?

Zoe
  • 27,060
  • 21
  • 118
  • 148
James Newton
  • 6,623
  • 8
  • 49
  • 113
  • Not sure what you mean by "without changing my history in any way". Git will move to the branch in question, and the commit history will be identical to what it has always been for that branch, before you entered a detached head state. – user229044 Aug 31 '15 at 22:08

1 Answers1

2

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.

user229044
  • 232,980
  • 40
  • 330
  • 338