我无意间把错误的档案 写错给Git 基特,但还没有将承诺推进到服务器上。
我如何解除那些承诺?当地当地仓库?
我无意间把错误的档案 写错给Git 基特,但还没有将承诺推进到服务器上。
我如何解除那些承诺?当地当地仓库?
当前回答
如何撤销最后的 Git 承诺 ?
为了让一切恢复到上次承诺之前的状态 我们需要重置在总部总部之前的承诺
如果你不想保留你所做的改变:
git reset --hard HEAD^
如果您想要保留您的更改 :
git reset --soft HEAD^
现在检查您的 git 日志。 它会显示我们上次的承诺已被删除 。
其他回答
另一种方式:
检查您想要返回的分支, 然后将本地工作副本重置到您想要在远程服务器上成为最新一份的承诺( 它将在离别后进行的一切) 。 要做到这一点, 请在 SupportTree I右键点击并选中的“ 重置 BranchNAME 以进行此承诺 ” 。
然后导航到仓库的本地目录并运行此命令 :
git -c diff.mnemonicprefix=false -c core.quotepath=false push -v -f --tags REPOSITORY_NAME BRANCHNAME:BRANCHNAME
这将删除您本地仓库中当前一个后的所有承诺, 但只删除该分支 。
如果你打算完全撤销一个本地的承诺, 无论你改变什么你对承诺所做的, 如果你对此不担心, 执行以下命令。
git reset --hard HEAD^1
(此命令将忽略您的全部任务, 您的更改将会从您的本地工作树上完全丢失) 如果您想要撤销您的承诺, 但是您想要您在中转区域中的更改( 之前要像在git add
)然后执行以下命令。
git reset --soft HEAD^1
现在,您的已执行文件将进入中转区域。 如果您想要提升文件, 您需要编辑错误的内容, 那么执行以下命令
git reset HEAD
现在承诺要将文件从舞台区域移到非舞台区域。 现在文件已准备编辑, 所以无论您改变什么, 您都想要去编辑和添加它, 并做出新的/ 新的承诺 。
为了撤销最后的本地承诺, 在不丢弃其改变的情况下, 我有一个便用的别名~/.gitconfig
[alias]
undo = reset --soft HEAD^
然后,我简单地使用git undo
这是超容易记住的。
通常我并不想撤销一连串的承诺, 而是编辑早先的承诺,
我发现自己经常去修修过去的东西 以至于我写了剧本
以下是工作流程:
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
使用 reflog 查找正确状态
git reflog
安全前的路线
选择正确的 reflog( 以我为例, f3cb6e2) 和类型
git reset --hard f3cb6e2
在那之后,重置的总部将重新设置为重置的总部。
冲突后的讲解
最终, 折叠图看起来像下面的图片
谈判最后定本