我无意间把错误的档案 写错给Git 基特,但还没有将承诺推进到服务器上。

我如何解除那些承诺?当地当地仓库?


当前回答

第一运行 :

git reflog

这将显示您在存储库中实施的所有可能的动作, 例如, 承诺、 合并、 调用等 。

那么,请:

git reset --hard ActionIdFromRefLog

其他回答

如何编辑编辑编辑编辑先前犯过

通常我并不想撤销一连串的承诺, 而是编辑早先的承诺,

我发现自己经常去修修过去的东西 以至于我写了剧本

以下是工作流程:

  1. git commit-edit <commit-hash>
    

    这将让您在您想要编辑的承诺上掉下来 。

    承诺的更改将是un un准备准备上场 如你所愿 这是第一次

  2. 并按你所希望的那样 确定并完成承诺

    (您可能想要使用)git stash save --keep-index来解开任何您没有做的文件)

  3. 重做承诺--amend, 例如 :

    git commit --amend
    
  4. 完成重定基数 :

    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 log 

然后你们可以做:

git reset --hard <commit_id>

git push origin <branch_name> -f

第一运行 :

git reflog

这将显示您在存储库中实施的所有可能的动作, 例如, 承诺、 合并、 调用等 。

那么,请:

git reset --hard ActionIdFromRefLog

为了消除(所有变化)最后承诺、最后2承诺和最后n承诺:

git reset --hard HEAD~1
git reset --hard HEAD~2
...
git reset --hard HEAD~n

在做出具体承诺后,要消除任何东西:

git reset --hard <commit sha>

例如,

git reset --hard 0d12345

谨慎使用硬选项 : 它会同时删除您回购的本地更改, 并返回到上一个提及的承诺 。 您只应该运行此选项, 前提是您确定您在最后一次承诺中搞砸了, 并且想要回到过去 。

作为副注释,大约7个承诺的散列字母就足够了,但在更大的项目中,你可能需要最多12个字母才能独有。如果您愿意,也可以使用整个承诺的 SHA 。

上述命令在GitHub也为Windows服务。

要撤销您的本地承诺, 您使用git reset <commit>也 。此辅助工具展示它是如何运作的 是非常有帮助的

或者,您也可以使用git revert <commit>: 恢复中当您想要添加另一个让更改倒转的承诺时, 应该使用它( 但将其保留在工程历史中 ) 。