我无意间把错误的档案 写错给Git 基特,但还没有将承诺推进到服务器上。
我如何解除那些承诺?当地当地仓库?
我无意间把错误的档案 写错给Git 基特,但还没有将承诺推进到服务器上。
我如何解除那些承诺?当地当地仓库?
当前回答
通过下列方式查看日志来查找上次承诺的散列代码 :
git log
然后
git reset <the previous co>
其他回答
你总是可以做一个git checkout <SHA code>
前一版本的版本, 然后再次承诺使用新代码 。
先决条件:当修改您存储库中的现有文件时,该修改最初被视为未阶段。为了实施修改,需要分阶段进行,这意味着使用索引
git add
。在一次任务操作中,被筛选的文件会被添加到索引中。
让我们举一个例子:
- A - B - C (master)
HEAD
点点到C
与索引匹配C
.
git reset --soft B
有意并打算删除承诺 C和将主控/ HEAD 指向 B. git status
您可以看到索引中的文件承诺 C计为阶段d. git commit
到此点将创建新承诺与C相同的变化git reset --mixed B
. git add
然后如往常地实践。git reset --hard B
希望这种对可供使用的旗帜的比较git reset
命令会帮助某人明智地使用它们。请参考这些以获取更多细节链接1 & 链接2
使用此命令
git checkout -b old-state 0d1d7fc32
为了撤销最后的本地承诺, 在不丢弃其改变的情况下, 我有一个便用的别名~/.gitconfig
[alias]
undo = reset --soft HEAD^
然后,我简单地使用git undo
这是超容易记住的。
通常我并不想撤销一连串的承诺, 而是编辑早先的承诺,
我发现自己经常去修修过去的东西 以至于我写了剧本
以下是工作流程:
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