我无意间把错误的档案 写错给Git 基特,但还没有将承诺推进到服务器上。
我如何解除那些承诺?当地当地仓库?
我无意间把错误的档案 写错给Git 基特,但还没有将承诺推进到服务器上。
我如何解除那些承诺?当地当地仓库?
当前回答
使用 reflog 查找正确状态
git reflog
安全前的路线
选择正确的 reflog( 以我为例, f3cb6e2) 和类型
git reset --hard f3cb6e2
在那之后,重置的总部将重新设置为重置的总部。
冲突后的讲解
最终, 折叠图看起来像下面的图片
谈判最后定本
其他回答
通常我并不想撤销一连串的承诺, 而是编辑早先的承诺,
我发现自己经常去修修过去的东西 以至于我写了剧本
以下是工作流程:
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 revert <commit-id>
.
为了得到身份证明 只需使用git log
.
每次我需要撤销承诺/承诺时,我要做的是:
git reset HEAD~<n>
/ 上次承诺的数量, 我需要撤销
git status
/ 可选。 所有文件现在都红色( 未预设 ) 。
现在,我可以添加并只承诺我所需要的文件 :
git add <file names> & git commit -m "message" -m "details"
git checkout <filename>
git push origin <branch name> -f
用 -f来强迫推撤销最后一次承诺的最简单方式是
git reset HEAD^
这将带来项目状态 之前,您已经做出承诺。