我无意间把错误的档案 写错给Git 基特,但还没有将承诺推进到服务器上。
我如何解除那些承诺?当地当地仓库?
我无意间把错误的档案 写错给Git 基特,但还没有将承诺推进到服务器上。
我如何解除那些承诺?当地当地仓库?
当前回答
以下是网站:Oh shit, git!
.
这里有许多解密的秘方 如何在Git 中解决事情。其中一些是:
哦,该死,我需要改变 信息在我的最后一次承诺!
git commit --amend
# follow prompts to change the commit message
哦,我无意中把什么东西 给了主人 本来该在全新的树枝上!
# Create a new branch from the current state of master
git branch some-new-branch-name
# Remove the commit from the master branch
git reset HEAD~ --hard
git checkout some-new-branch-name
# Your commit lives in this branch now :)
其他回答
使用此命令
git checkout -b old-state 0d1d7fc32
通常情况下,你想要取消对因为您犯了一个错误,所以您想要修正它 基本上就是OP在问问题时所做的。真的,您真的想要复复做a 承诺。
这里的大多数答案都集中在命令行上。 虽然命令行是使用Git的最佳方法, 当你对它感到舒服的时候, 它可能与来自其他版本控制系统到 Git 的人有点不同。
使用 GUI 如何操作。 如果您安装了 Git, 您已经拥有了所有您需要遵守的指示 。
注:我在这里假设您在推动前意识到承诺是错误的。 如果您不知道推力意味着什么, 那么您可能还没有推动。 继续执行指令 。 如果您推动错误承诺, 最危险的方法就是跟踪错误承诺, 并做出新的承诺, 来修补事情, 您在版本控制系统中这样做的方式不允许您重写历史 。
使用图形用户界面来修正你最近的过错:
git gui
通常我并不想撤销一连串的承诺, 而是编辑早先的承诺,
我发现自己经常去修修过去的东西 以至于我写了剧本
以下是工作流程:
git commit-edit <commit-hash>
这将让您在您想要编辑的承诺上掉下来 。
承诺的更改将是un un准备准备上场 如你所愿 这是第一次
并按你所希望的那样 确定并完成承诺
(您可能想要使用)git stash save --keep-index
来解开任何您没有做的文件)
重做承诺--amend
, 例如 :
git commit --amend
完成重定基数 :
git rebase --continue
以下调作以下调作以下调作以下调作以下调作以下调作以下调作以下调作以下调作以下调作git-commit-edit
把它放在你的$PATH
:
#!/bin/bash
# Do an automatic git rebase --interactive, editing the specified commit
# Revert the index and working tree to the point before the commit was staged
# https://stackoverflow.com/a/52324605/5353461
set -euo pipefail
script_name=${0##*/}
warn () { printf '%s: %s\n' "$script_name" "$*" >&2; }
die () { warn "$@"; exit 1; }
[[ $# -ge 2 ]] && die "Expected single commit to edit. Defaults to HEAD~"
# Default to editing the parent of the most recent commit
# The most recent commit can be edited with `git commit --amend`
commit=$(git rev-parse --short "${1:-HEAD~}")
# Be able to show what commit we're editing to the user
if git config --get alias.print-commit-1 &>/dev/null; then
message=$(git print-commit-1 "$commit")
else
message=$(git log -1 --format='%h %s' "$commit")
fi
if [[ $OSTYPE =~ ^darwin ]]; then
sed_inplace=(sed -Ei "")
else
sed_inplace=(sed -Ei)
fi
export GIT_SEQUENCE_EDITOR="${sed_inplace[*]} "' "s/^pick ('"$commit"' .*)/edit \\1/"'
git rebase --quiet --interactive --autostash --autosquash "$commit"~
git reset --quiet @~ "$(git rev-parse --show-toplevel)" # Reset the cache of the toplevel directory to the previous commit
git commit --quiet --amend --no-edit --allow-empty # Commit an empty commit so that that cache diffs are un-reversed
echo
echo "Editing commit: $message" >&2
echo
如果你们在本地做出你们不喜欢的事,而他们还没有被推倒,而你们却可以把事情重现为以往的善事。这好像坏事从未发生过。下面是这样的:
在您的终端中( 终端、 Git Bash 或 Windows 命令提示) , 浏览到您的 Git repo 的文件夹中。 运行 git 状态, 并确保您有干净的工作树。 每个承诺都有一个独特的散列( 看起来像 2f5451f ) 。 您需要找到最后一件好事的散列( 您想要返回到哪个地方 ) 。 这里有两个地方您可以看到要承诺的散列 : 在 GitHub 或 Bitbucket 网站或网站的承诺历史中 。 在您的终端中( 终端、 Git Bash 或 Windows 命令快递) 运行命令 git 日志 -- 在线, 一旦您知道最后一件好事的仓列( 您想要返回到哪个地方) , 请运行以下的命令( 将 2f5451f 与您的承诺重写 ) :
git reset 2f5451f
git reset --hard 2f5451f
注:如果您确实重置了承诺, 承诺将被删除, 但更改将显示为未承诺, 允许您访问代码 。 这是最安全的选项, 因为也许您想要一些代码, 现在您可以做出一些好的更改和新承诺 。 通常您会想要撤销承诺, 丢弃代码, 这正是 Git 重置 -- 硬键所做的 。