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

其他回答

作为以下步骤。

步骤1

命中git log

从日志列表中找到最后的硬化散列代码, 然后输入 :

步骤2

git reset <hash code>

假设您在本地犯下错误, 并将其推到远程仓库。 您可以解开这两个命令的混乱 :

首先,我们需要纠正我们的地方储存库,回到我们所希望的承诺上来:

git reset --hard <previous good commit id where you want the local repository  to go>

现在,我们通过使用此命令,在远程仓库大力推动这项良好承诺:

git push --force-with-lease

强制选项的“ 租赁” 版本将防止意外删除您不知道的新承诺( 即上次拉动后来自其它来源 ) 。

头:

在重置承诺之前, 我们应该知道关于 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

git reset --soft HEAD~1

git status

Output

在分母上
您的分行在“ 来源/ 主机” 前面 1 个承诺 。
(使用“ little push” 发布您的本地承诺)

拟承诺的修改:
(使用“ git reconful -- paged...” 到 unstage) 新文件 : file1

git log --oneline --graph

Output

  • 90f8bb1 (HEAD - > 主人) 第二次承诺\
  • 7083e29 初始仓库承诺

您可以使用git reset unwanted_file命令您不想进入阶段的文件 。 通过使用此命令, 我们可以将更改的文件从中继区域移到工作目录 。

我如何在本地及远程解析 Git 承诺?