git commit error how to do ~

Fixed an issue I commit error, the reproduced record it -
draw the focus must git commit before using git reset -hard (this parameter toxic) or git add or git stash either. . .
If you do not perform these operations, then there is a blogger for years to find a method to save. . .
It was a stormy night, bloggers head 100m stretch of lightning, thunder down, wow Kaka! Bloggers across time and space before not to rest! ! Ha ha ha ha day must be a way ah! ! !
"Turn" Notes Git commit revocation of http://www.cnblogs.com/scodong/p/4757378.html
Git commit undo operations command git reset -hard HEAD ^

First, the new three documents, demo1, demo2, demo3
Here Insert Picture Description

Two, git add commands submitted to the staging area, git reset HEAD demo1 file is to be submitted to the staging area where the revocation.
Write pictures described here

The above chart, git reset HEAD demo1 demo1 will to withdraw from scratch, and now is untracked.

Three, git commit submit local repository
Write pictures described here

The picture above, git commit submit demo2, demo3 to a local warehouse.

Fourth, now want to commit before the withdrawal, you can use git reset -hard HEAD ^ command
Write pictures described here

A third step, the first demo2 commit, commit Demo3 again, so that is now commit HEAD value of Demo3.

(HEAD is pointing to the latest submission, the submission is the HEAD , the last time the HEAD ^, can also be written HEAD ~ 2, and so on)

So git reset -hard HEAD is to demo3 out the latest submitted revoked, the revocation is very thorough, local file will be deleted. - Why so much special you are to put the phrase on the top ah

<转>恢复 git reset -hard 的误操作 ——这是有commit操作的,之前要有这操作,我还来百度?
此部分内容转自:https://www.cnblogs.com/mliudong/archive/2013/04/08/3007303.html

有时候使用Git工作得小心翼翼,特别是涉及到一些高级操作,例如 reset, rebase 和 merge。甚至一些很小的操作,例如删除一个分支,我都担心数据丢失。

不久之前,我在做一些大动作(rebasing)之前,我总是备份整个版本库,以防万一。直到最近我才发现git的历史记录是不可修改的,也就是说你不能更改任何已经发生的事情。你做的任何操作都只是在原来的操作上修改。也就是说,即使你删除了一个分支,修改了一个提交,或者强制重置,你仍然可以回滚这些操作。

让我们来看一些例子:

gitinit touch foo.txt
gitaddfoo.txt git commit -m “initial commit”

echo‘newdata′>>foo.txt git commit -a -m “more stuff added to foo”

你现在看git的历史记录,你可以看到两次提交:
$ git log

  • 98abc5a (HEAD, master) more stuff added to foo
  • b7057a9 initial commit

现在让我们来重置回第一次提交的状态:
gitreset–hardb7057a9 git log

  • b7057a9 (HEAD, master) initial commit

It looks like we lost our second submission, there is no way to get it back. But reflog is used to solve this problem. Simply put, it will record the history of all HEAD, that is when you do reset, checkout and other operations, these operations will be recorded in the reflog.

$ git reflog
b7057a9 HEAD@{0}: reset: moving to b7057a9
98abc5a HEAD@{1}: commit: more stuff added to foo
b7057a9 HEAD@{2}: commit (initial): initial commit

So, we have to get back our second commit, only need to do the following operations:
$ git the RESET -hard 98abc5a

Then look at the record git:
$ git log

  • 98abc5a (HEAD, master) more stuff added to foo
  • b7057a9 initial commit

So, if you time because of reset operations such as the loss of a submission, you can always get it back. Unless your future as a waste disposal operation has been lost git, generally 30 days

Turn: https://www.cnblogs.com/hope-markup/p/6683522.html
- this man was still on point spectrum, there are add recovery after the operation.

Guess you like

Origin blog.csdn.net/baidu_26954625/article/details/93194669
Recommended