我无意间把错误的档案 写错给Git 基特,但还没有将承诺推进到服务器上。
我如何解除那些承诺?当地当地仓库?
我无意间把错误的档案 写错给Git 基特,但还没有将承诺推进到服务器上。
我如何解除那些承诺?当地当地仓库?
当前回答
git reset --soft HEAD~1
重置将会将您当前的 HEAD 分支倒带到指定的修订版 。
Note排--soft
旗帜 : 这样可以确保未撤销修改中的更改被保存。 在运行命令后, 您会发现这些更改是您工作副本中未承诺的本地修改 。
如果您不想保留这些修改,只需使用--hard
。确保只在确定不再需要这些更改时才这样做。
git reset --hard HEAD~1
撤消多个提交文件
git reset --hard 0ad5a7a6
但是,记住,使用重置命令可以解除所有在你返回后的承诺:
其他回答
要重置上一个修订版, 请永久删除所有未承诺的更改 :
git reset --hard HEAD~1
类型类型类型git log
并发现最后的散列代码,然后输入:
git reset <the previous co>
通常情况下,你想要取消对因为您犯了一个错误,所以您想要修正它 基本上就是OP在问问题时所做的。真的,您真的想要复复做a 承诺。
这里的大多数答案都集中在命令行上。 虽然命令行是使用Git的最佳方法, 当你对它感到舒服的时候, 它可能与来自其他版本控制系统到 Git 的人有点不同。
使用 GUI 如何操作。 如果您安装了 Git, 您已经拥有了所有您需要遵守的指示 。
注:我在这里假设您在推动前意识到承诺是错误的。 如果您不知道推力意味着什么, 那么您可能还没有推动。 继续执行指令 。 如果您推动错误承诺, 最危险的方法就是跟踪错误承诺, 并做出新的承诺, 来修补事情, 您在版本控制系统中这样做的方式不允许您重写历史 。
使用图形用户界面来修正你最近的过错:
git gui
在回答之前,我们补充一些背景,解释一下这是什么HEAD
.
First of all what is HEAD?
HEAD
仅指当前分支的当前承诺(最新承诺)。
只有一个,只有一个,只有一个HEAD
在任何给定时间。 (不包括git worktree
)
内容的内容HEAD
存储在内部.git/HEAD
并包含当前承诺的 40 字节 SHA-1 。
detached HEAD
如果你们不履行最近的承诺,那末,HEAD
指在历史中先前承诺detached HEAD
.
在命令线上,它会看起来像这个——SHA-1,而不是自HEAD
不指向当前分支的一端
git checkout
git checkout <commit_id>
git checkout -b <new branch> <commit_id>
git checkout HEAD~X // x is the number of commits t go back
这将检查指向想要的承诺的新分支 。
此命令将检出给给定的承诺 。
此时此刻,您可以创建一个分支,并从此开始工作。
# 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>
git reflog
你可以随时使用reflog
并且,还有。
git reflog
将显示更新HEAD
并检查想要的 reflog 条目将设置HEAD
返回到此任务。
总部总部每次修改时,将有一个新的条目。reflog
git reflog
git checkout HEAD@{...}
这样你就可以回到你想要的事业了
git reset --hard <commit_id>
"移动"你的总部 回到想要的承诺。
# This will destroy any local modifications.
# Don't do it if you have uncommitted work you want to keep.
git reset --hard 0d1d7fc32
# Alternatively, if there's work to keep:
git stash
git reset --hard 0d1d7fc32
git stash pop
# This saves the modifications, then reapplies that patch after resetting.
# You could get merge conflicts if you've modified things which were
# changed since the commit you reset to.
git rebase --no-autostash
并且,还有。git revert <sha-1>
“ 撤消” 指定的承诺或承诺范围 。
重置命令将“ 撤消” 对给定任务所做的任何更改 。
将使用解析补丁进行新承诺, 而原始承诺也将保留在历史中 。
# add new commit with the undo of the original one.
# the <sha-1> can be any commit(s) or commit range
git revert <sha-1>
这个计划说明哪个指挥所做什么。
如你所见reset && checkout
修改HEAD
.