git:放弃对当前签出版本的更改

时间:2015-08-31 22:05:46

标签: git git-checkout

我查看了我项目的早期版本,使用:

$ git checkout fd4a4a1

回应是:

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>

我复制了一大堆代码,但没有做任何更改。我现在想回到当前的分支。但是,当我跑...

git checkout myCurrentBranch

... git抱怨:

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

我不关心这些变化。如果它们被制造出来,就会无意中发生。是否可以强制git忽略这些更改并检查我当前的分支,而不以任何方式更改我的历史记录?

1 个答案:

答案 0 :(得分:2)

  

是否可以强制git忽略这些更改并检查我当前的分支,而不以任何方式更改我的历史记录?

是的,使用git checkout -f <branchname>来强迫&#34;结账将发生,无论是否会破坏任何未提交的更改。