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

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


当前回答

要重置上一个修订版, 请永久删除所有未承诺的更改 :

git reset --hard HEAD~1

其他回答

头:

在重置承诺之前, 我们应该知道关于 HEAD... HEAD 在您的工作目录中只是您目前的状况。 它由承诺编号代表 。

Git 承诺 :

在由独有标签代表的一承诺下指定的每一项更改。 无法删除提交 。 所以, 如果您想要您最后的承诺, 您可以简单地跳入其中 。git reset.

您可以使用两种方法跳入最后一个承诺 :

方法1:(如果你不知道承诺编号,但想移动到第一个)

git reset HEAD~1  # It will move your head to last commit

方法2:(如果你们知道自己所做的一切,那末,你们只须将自己所知道的(事情)重新置身于你们所认识的(事情)中)

git reset 0xab3# 提交编号

注:想要了解最近一项任务尝试git log -p -1

以下是图形表达式 :

Enter image description here

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

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

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

以下是工作流程:

  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:

git reset --soft HEAD~1

解释:什么什么是git reset基本上reset任何承诺,如果你愿意 回去,如果你把它和--soft键,它将返回,但保留您文件中的更改,所以您可以回到刚刚添加文件的阶段,HEAD是分支的首脑,如果结合了~1(在这种情况下,你们也使用)HEAD^,它会回去 只有一个承诺 你想要什么...

我为您创建了以下图像中的步骤, 详情更多, 包括所有在真实情况下可能发生的步骤, 并承诺执行代码 :

How to undo the last commits in Git?

撤销上次承诺 :

git reset --soft HEAD^ or git reset --soft HEAD~

这将撤销最后一项承诺 。

--soft意思是重置为中位 。

HEAD~ or HEAD^意思是移动以在 HEAD 之前承诺 。

替换上次承诺的新承诺:

git commit --amend -m "message"

它将以新承诺取代最后一项承诺 。

如果您想要还原最后一个任务, 但仍要保留在任务中本地作出的更改, 请使用此命令 :

git reset HEAD~1 --mixed