我无意间把错误的档案 写错给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

其他回答

如何撤销最后的 Git 承诺 ?

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

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

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

    git reset --soft HEAD^
    

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

enter image description here

假设您在视觉工作室工作, 如果您进入分支历史, 并查看您的所有承诺, 只需在承诺之前选择事件, 您想要撤销, 右单击它, 然后选择Revert轻而易举

当地承诺

git reset --soft HEAD~1

或者如果你们记不起来,那末,你们可以使用

git rm --cached <file>

用于被推动的 承诺

从存储库历史中移除文件的正确方式正在使用git filter-branch。也就是说,

git filter-branch --index-filter 'git rm --cached <file>' HEAD

但我建议您谨慎使用此命令。 更多信息git-过滤器-分栏(1) 手册.

git reset --soft HEAD~1

软性 : 这将只从本地端删除承诺, 并保留文件所做的更改 。

    git reset --hard HEAD~1
    git push origin master

硬性 : 这将从本地和远程删除承诺, 并删除文件中所做的更改 。

你总是可以做一个git checkout <SHA code>前一版本的版本, 然后再次承诺使用新代码 。