And*_*aus 6 git husky lint-staged git-husky
这是我所做的:
git status 显示我的所有更改。git add -Agit commit -m "Foo". 预提交的 git 钩子用husky和触发lint-staged。git commit -m "Foo"一次,立即取消了。git status是干净的,git log并且git reflog不显示新的提交。为什么我的更改被还原?我如何恢复它们?
And*_*aus 13
好吧,这是lint-staged罪魁祸首。它隐藏了我的更改。
所以跑步git stash apply恢复了他们!
对于以下所有人:TL;DR
-选项 1 - 您提到过您已经这样做了:使用git reflog&& git reset
-选项 2 - 使用您的编辑器历史记录
-选项 3 - 如果您添加了这些文件,请从暂存区域获取它们,但您将需要找到他们
# Find all dangling files
git fsck --all
## Now use git cat-file -p to print those hashes
git cat-p <SHA-1>
Run Code Online (Sandbox Code Playgroud)
在回答之前,让我们添加一些背景知识,解释一下这HEAD是什么。
First of all what is HEAD?HEAD只是对当前分支上的当前提交(最新)的引用。在任何给定时间
只能有一个(不包括)。HEADgit worktree
HEAD里面存储的内容.git/HEAD是当前提交的40字节SHA-1。
detached HEAD如果您不是最新的提交 - 这意味着它HEAD指向历史记录中的先前提交,则称为detached HEAD.
在命令行上,它看起来像这样 - SHA-1 而不是分支名称,因为HEAD不指向当前分支的尖端:
git checkoutgit checkout <commit_id>
git checkout -b <new branch> <commit_id>
git checkout HEAD~X // x is the number of commits t go back
Run Code Online (Sandbox Code Playgroud)
这将签出指向所需提交的新分支。
此命令将签出给定的提交。
此时,您可以创建一个分支并从此时开始工作。
# Checkout a given commit.
# Doing so will result in a `detached HEAD` which mean that the `HEAD`
# is not pointing to the latest so you will need to checkout branch
# in order to be able to update the code.
git checkout <commit-id>
# Create a new branch forked to the given commit
git checkout -b <branch name>
Run Code Online (Sandbox Code Playgroud)
git reflogreflog您也可以随时使用。
git reflog将显示更新的任何更改HEAD,并检查所需的引用日志条目将设置HEAD回此提交。
每次修改 HEAD 时,都会在 HEAD 中产生一个新条目reflog
git reflog
git checkout HEAD@{...}
Run Code Online (Sandbox Code Playgroud)
这会让你回到你想要的提交
git reset --hard <commit_id>将您的 HEAD“移”回所需的提交。
# Find all dangling files
git fsck --all
## Now use git cat-file -p to print those hashes
git cat-p <SHA-1>
Run Code Online (Sandbox Code Playgroud)
git rebase --no-autostash。git revert <sha-1>“撤消”给定的提交或提交范围。
重置命令将“撤消”给定提交中所做的任何更改。
将提交带有撤消补丁的新提交,而原始提交也将保留在历史记录中。
git checkout <commit_id>
git checkout -b <new branch> <commit_id>
git checkout HEAD~X // x is the number of commits t go back
Run Code Online (Sandbox Code Playgroud)
此架构说明了哪个命令执行什么操作。
如您所见,reset && checkout修改HEAD.
| 归档时间: |
|
| 查看次数: |
2036 次 |
| 最近记录: |