我无意中把错误的文件给了Git, 但还没有把承诺推到服务器上。
我如何从当地存储库撤销这些承诺?
我无意中把错误的文件给了Git, 但还没有把承诺推到服务器上。
我如何从当地存储库撤销这些承诺?
当前回答
另一种方式:
检查您想要返回的分支, 然后将本地工作副本重置到您想要在远程服务器上成为最新一份的承诺( 它将在离别后进行的一切) 。 要做到这一点, 请在 SupportTree I右键点击并选中的“ 重置 BranchNAME 以进行此承诺 ” 。
然后导航到仓库的本地目录并运行此命令 :
git -c diff.mnemonicprefix=false -c core.quotepath=false push -v -f --tags REPOSITORY_NAME BRANCHNAME:BRANCHNAME
这将删除您本地仓库中当前一个后的所有承诺, 但只删除该分支 。
其他回答
头:
在重置承诺之前, 我们应该知道关于 HEAD... HEAD 在您的工作目录中只是您目前的状况。 它由承诺编号代表 。
Git 承诺 :
在由独有标记表示的一承诺下指定的每项更改。 无法删除提交。 所以, 如果您想要您最后的承诺, 您可以使用 git 重设来跳入它 。
您可以使用两种方法跳入最后一个承诺 :
方法1:(如果不知道承诺编号,但想移动到第一个)
git reset HEAD~1 # It will move your head to last commit
方法2: (如果知道您只需将承诺重置到您已知的承诺上)
git 重置 0xab3 # 提交编号
注意: 如果您想要了解最近一个尝试 git 日志 - p - 1 的最近运行尝试
以下是图形表达式 :
调
引用: 如何撤销 Git 中的最后一次承诺 ?
如果您已经安装了 Git 扩展名, 您可以很容易撤销/ 撤销任何任务( 您可以从这里下载 Git 扩展名 ) 。
打开 Git 扩展名, 右键单击您想要返回的承诺, 然后选择“ 回溯承诺 ” 。
调
将打开弹出( 见下文截图)
调
选择“自动创建一项承诺”,如果您想要直接进行已恢复的更改,或者如果您想要手动进行已恢复的更改,则保留未选中的框,单击“撤销此承诺”按钮。
如何编辑上一个承诺
通常我并不想撤销一连串的承诺, 而是编辑早先的承诺,
我发现自己经常去修修过去的东西 以至于我写了剧本
以下是工作流程:
git exent- edit <commit- hash> 这将让您在您想要编辑的承诺时丢弃您。 承诺的更改将会被卸下, 将按您希望的第一次进行, 并准备按您希望的第一次进行。 固定并按您希望的, 并按您希望的原初阶段进行承诺 。 (您可能想要使用 git 隐藏保存 -- kep- index 来抓松任何您没有执行的文件) 重做承诺 -- amend, 例如: git 承诺 -- amend compult the rebase: 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 承诺 : 首先, 您可以使用 Git 返回, 如果您想要保留您的承诺历史 :
git revert HEAD~3
git revert <hashcode of commit>
第二是您可以使用 Git 重置, 这将删除您全部的委托历史, 并随心所欲地将您的头移到您想要的地方 。
git reset <hashcode of commit>
git reset HEAD~3
您也可以使用 -- hard 关键词, 如果有的话, 如果它开始有其他行为的话。 但是, 我建议在非常必要的时候使用它。
IntelliJIDEA 您可以按 Alt+9 键右键单击承诺列表中的某些标签打开 Git 仓库日志, 然后选择 : “ 将当前分支重置到这里... ” 。