我无意间把错误的档案 写错给Git 基特,但还没有将承诺推进到服务器上。
我如何解除那些承诺?当地当地仓库?
我无意间把错误的档案 写错给Git 基特,但还没有将承诺推进到服务器上。
我如何解除那些承诺?当地当地仓库?
当前回答
$ git commit -m "Something terribly misguided" # (0: Your Accident)
$ git reset HEAD~ # (1)
[ edit files as necessary ] # (2)
$ git add . # (3)
$ git commit -c ORIG_HEAD # (4)
git reset
是负责取消对。它会解除您最后的承诺,而您的工作树( 您在磁盘上的文件状态) 尚未被移动 。在你再次犯下罪行之前,你需要再加一次)。git add
任何您想要包含在您新承诺中的内容 。reset
复制旧头头到.git/ORIG_HEAD
; commit
与-c ORIG_HEAD
将打开编辑器,该编辑器最初包含旧承诺的日志消息,并允许您编辑它。如果不需要编辑该消息,您可以使用该-C
选项。或者编辑上一个承诺( 或仅其承诺信件), commit --amend
将在当前索引内对上一个承诺添加变化。
要删除( 不再返回) 被推到服务器的承付重写历史git push origin main --force[-with-lease]
这是必要的。这是几乎几乎总是使用一个坏主意--force
; 偏; 更优--force-with-lease
改为,如以下所示:Git 手册:
如果你[重写历史]已经发表,你应该了解重写历史的意义。
您可以使用git reflog
确定 SHA-1用于您想要返回的承诺。 一旦您拥有此值, 请使用上文解释的顺序命令 。
HEAD~
与HEAD~1
该条什么是头在Git?如果您想要解开多项承诺, 将会很有帮助 。
其他回答
使用使用git revert <commit-id>
.
要拿到身份证明,请使用git log
.
通常我并不想撤销一连串的承诺, 而是编辑早先的承诺,
我发现自己经常去修修过去的东西 以至于我写了剧本
以下是工作流程:
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 的图形工具) 查看您的承诺和树。 您可以单击右键手动重置它 。
每个人都以如此复杂的方式发表意见。
如果您想要从分支中删除最后一项承诺, 最简单的方法是:
git reset --hard HEAD~1
现在,为了摆脱你最后的承诺,你必须
git push --force
这就对了,这会消除你最后的承诺
撤销最后一次承诺的最简单方式是
git reset HEAD^
这将带来项目状态 之前,您已经做出承诺。