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

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


当前回答

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

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

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

Git Extensions screen shot

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

Revert commit popup

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

其他回答

我验证了所提议的有效方法,这里就是使用这一方法的一个具体例子:

如果您想要永久撤销/取消您的最后一项承诺(等等, 一个一个一个, 尽可能多) , 有三个步骤 :

1: 获取您想要到达的承诺的 id = SHA, 当然

$ git log

2: 删除您先前的承诺

$ git reset --hard 'your SHA'

3: 将新的本地历史强制在您的原籍 GitHub 与-f选项( 将从 GitHub 历史中删除最后的磁轨)

$ git push origin master -f

示例示例示例示例

$ git log

最后一次承诺取消

commit e305d21bdcdc51d623faec631ced72645cca9131 (HEAD -> master, origin/master, origin/HEAD)
Author: Christophe <blabla@bla.com>
Date:   Thu Jul 30 03:42:26 2020 +0200

U2_30 S45; updating files package.json & yarn.lock for GitHub Web Page from docs/CV_Portfolio...

现在就向总部提交我们想要的文件

commit 36212a48b0123456789e01a6c174103be9a11e61
Author: Christophe <blabla@bla.com>
Date:   Thu Jul 30 02:38:01 2020 +0200

First commit, new title

删除最后一项, 达到承诺前, 删除最后一项

$ git reset --hard 36212a4

HEAD is now at 36212a4 First commit, new title

检查一下,没事的

$ git log

commit 36212a48b0123456789e01a6c174103be9a11e61 (HEAD -> master)
Author: Christophe <blabla@bla.com>
Date:   Thu Jul 30 02:38:01 2020 +0200

    First commit, new title

$ git status

On branch master
Your branch is behind 'origin/master' by 1 commit, and can be fast-forwarded.
 (use "git pull" to update your local branch)

nothing to commit, working tree clean

更新 Git (Hub) 上的历史

$ git push origin master -f

Total 0 (delta 0), reused 0 (delta 0), pack-reused 0
To https://github.com/ GitUser bla bla/React-Apps.git
 + e305d21...36212a4 master -> master (forced update)

检查一下,没事的

$ git status

On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean
git reset --soft HEAD~1

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

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

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

只需撤销最后一项承诺 :

git reset --soft HEAD~

或撤销上次承诺前的时间 :

git reset --soft HEAD~2

或撤销先前的任何承诺 :

git reset --soft <commitID>

(您可以使用git reflog)

当您撤销上一个任务时, 记住要用

git clean

更多信息,请查看以下文件:git- reseet 重置

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

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

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

以下是工作流程:

  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