我无意间把错误的档案 写错给Git 基特,但还没有将承诺推进到服务器上。
我如何解除那些承诺?当地当地仓库?
我无意间把错误的档案 写错给Git 基特,但还没有将承诺推进到服务器上。
我如何解除那些承诺?当地当地仓库?
当前回答
通常我并不想撤销一连串的承诺, 而是编辑早先的承诺,
我发现自己经常去修修过去的东西 以至于我写了剧本
以下是工作流程:
git commit-edit <commit-hash>
这将让您在您想要编辑的承诺上掉下来 。
承诺的更改将是un un准备准备上场 如你所愿 这是第一次
并按你所希望的那样 确定并完成承诺
(您可能想要使用)git stash save --keep-index
来解开任何您没有做的文件)
重做承诺--amend
, 例如 :
git commit --amend
完成重定基数 :
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 工程根 。 如果您使用视觉工作室, 请单击小组小组, 同步同步并点击下面的“打开命令提示”(见图像) 。
一旦进入CMD, 继续使用以下两个指示。
git fetch --all
那你就做
git reset --hard origin/master
这将覆盖 Git 服务器上的现有本地版本 。
您可以从本地仓库撤销您的承诺 。 请遵循以下方案 。
在下面的图像中, 我检查“ 测试” 分支( 使用 Git 命令)git checkout -b test
)作为本地检查状态(使用 Git 命令)git status
地方分支中没有任何可承诺的。
在下一个图像图像中,您可以看到这里的图像 我做了一些修改过滤器1. txt然后用一些信息(使用 Git 命令) 将文件添加到中继区, 并用一些信息( 使用 Git 命令) 来进行更改git commit -m "Doing commit to test revert back"
).
"-m 用于发送信件"
在下一个图像中,您可以看到您承诺的日志,无论您承诺什么(使用 Git 命令)git log
).
所以在以上图像中,您可以看到每个承诺的承付代号, 以及您现在的执信信息, 无论您想要返回或撤消的复制件, 即实施 ID 并击中下面的 Git 命令,git revert {"paste your commit id"}
示例:
git revert 9ca304ed12b991f8251496b4ea452857b34353e7
我恢复了上次的承诺。 现在, 如果您检查您的 Git 状态, 您可以看到修改后的文件过滤器1. txt并且尚未承诺。
git diff + git 应用程序是迄今为止我团队的最好选择, 清洁和非常容易, 不仅对最后一次任务来说
为了撤销最后的本地承诺, 在不丢弃其改变的情况下, 我有一个便用的别名~/.gitconfig
[alias]
undo = reset --soft HEAD^
然后,我简单地使用git undo
这是超容易记住的。
如果你们在本地做出你们不喜欢的事,而他们还没有被推倒,而你们却可以把事情重现为以往的善事。这好像坏事从未发生过。下面是这样的:
在您的终端中( 终端、 Git Bash 或 Windows 命令提示) , 浏览到您的 Git repo 的文件夹中。 运行 git 状态, 并确保您有干净的工作树。 每个承诺都有一个独特的散列( 看起来像 2f5451f ) 。 您需要找到最后一件好事的散列( 您想要返回到哪个地方 ) 。 这里有两个地方您可以看到要承诺的散列 : 在 GitHub 或 Bitbucket 网站或网站的承诺历史中 。 在您的终端中( 终端、 Git Bash 或 Windows 命令快递) 运行命令 git 日志 -- 在线, 一旦您知道最后一件好事的仓列( 您想要返回到哪个地方) , 请运行以下的命令( 将 2f5451f 与您的承诺重写 ) :
git reset 2f5451f
git reset --hard 2f5451f
注:如果您确实重置了承诺, 承诺将被删除, 但更改将显示为未承诺, 允许您访问代码 。 这是最安全的选项, 因为也许您想要一些代码, 现在您可以做出一些好的更改和新承诺 。 通常您会想要撤销承诺, 丢弃代码, 这正是 Git 重置 -- 硬键所做的 。