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

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


当前回答

如果你还想背到最后承诺 并改过历史

在命令下方使用, 表示您想要跳到前一个任务, 因为前一个任务已经存在 ID SHA -71e2,e57458bde883a37b332035f784c6653ec509中,您可以指向此承诺,在此承诺之后不会显示任何日志消息,此后所有历史都将被删除。

git 推进源 + 71e2e57458bde883a37b332035f784c6653ec509: 技术主管

其他回答

我通常首先会发现我最近所作所为的杂草:

git log

看起来是这样的:commit {long_hash}

复制此副本long_hash并重置它(回到相同的文件/声明在承诺上):

git reset --hard {insert long_hash without braces}

通常情况下,你想要取消对因为您犯了一个错误,所以您想要修正它 基本上就是OP在问问题时所做的。真的,您真的想要复复做a 承诺。

这里的大多数答案都集中在命令行上。 虽然命令行是使用Git的最佳方法, 当你对它感到舒服的时候, 它可能与来自其他版本控制系统到 Git 的人有点不同。

使用 GUI 如何操作。 如果您安装了 Git, 您已经拥有了所有您需要遵守的指示 。

注:我在这里假设您在推动前意识到承诺是错误的。 如果您不知道推力意味着什么, 那么您可能还没有推动。 继续执行指令 。 如果您推动错误承诺, 最危险的方法就是跟踪错误承诺, 并做出新的承诺, 来修补事情, 您在版本控制系统中这样做的方式不允许您重写历史 。

使用图形用户界面来修正你最近的过错:

  1. 导航到命令行的仓库,并用git gui
  2. 选择“ 修正上一个任务 ” 。 您将会看到您上次的委托信件、 您所准备的文件 以及您没有的文件 。
  3. 现在将事情更改为您想要它们查看的方式, 并单击 CON 。

参考:如何撤销在 Git 的最后一次承诺 ?

如果您已经安装了 Git 扩展名, 您可以很容易撤销/ 撤销任何连接( 您可以下载 Git 扩展名)在这里).

打开 Git 扩展名, 右键单击您想要返回的承诺, 然后选择“ 回溯承诺 ” 。

Git Extensions screen shot

将打开弹出( 见下文截图)

Revert commit popup

选择“自动创建一项承诺”,如果您想要直接进行已恢复的更改,或者如果您想要手动进行已恢复的更改,则保留未选中的框,单击“撤销此承诺”按钮。

如何撤销最后的 Git 承诺 ?

为了让一切恢复到上次承诺之前的状态 我们需要重置在总部总部之前的承诺

  1. 如果你不想保留你所做的改变:

    git reset --hard HEAD^
    
  2. 如果您想要保留您的更改 :

    git reset --soft HEAD^
    

现在检查您的 git 日志。 它会显示我们上次的承诺已被删除 。

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

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

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

以下是工作流程:

  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