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

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


当前回答

使用 reflog 查找正确状态

git reflog

reflog before 安全前的路线

选择正确的 reflog( 以我为例, f3cb6e2) 和类型

git reset --hard f3cb6e2

在那之后,重置的总部将重新设置为重置的总部。reset effect 冲突后的讲解

最终, 折叠图看起来像下面的图片

reflog after 谈判最后定本

其他回答

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

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

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

以下是工作流程:

  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

如果存储库是在当地承诺的,但尚未被推到服务器上,那么另一种粗糙/佣人解决它的方法将是:

  1. Git 复制另一个位置的仓库 。
  2. 将修改( 文件/ 目录) 从原始仓库复制到此新仓库。 然后承诺并按下新仓库的修改 。
  3. 将旧仓库替换为此新仓库 。

您可以使用git revert <commit-id>.

为了得到身份证明 只需使用git log.

每次我需要撤销承诺/承诺时,我要做的是:

  1. git reset HEAD~<n>/ 上次承诺的数量, 我需要撤销

  2. git status/ 可选。 所有文件现在都红色( 未预设 ) 。

  3. 现在,我可以添加并只承诺我所需要的文件 :

  • git add <file names> & git commit -m "message" -m "details"
  1. 可以选择:我可以将其它文件的更改(如果需要的话) 推回到它们以前的状态, 并进行退票:
  • git checkout <filename>
  1. 如果我已经把它推向了遥远的起源, 之前:
  • git push origin <branch name> -f用 -f来强迫推

撤销最后一次承诺的最简单方式是

git reset HEAD^

这将带来项目状态 之前,您已经做出承诺。