我无意间把错误的档案 写错给Git 基特,但还没有将承诺推进到服务器上。
我如何解除那些承诺?当地当地仓库?
我无意间把错误的档案 写错给Git 基特,但还没有将承诺推进到服务器上。
我如何解除那些承诺?当地当地仓库?
当前回答
撤销上次承诺 :
git reset --soft HEAD^ or git reset --soft HEAD~
这将撤销最后一项承诺 。
给--soft
意思是重置为中位 。
HEAD~ or HEAD^
意思是移动以在 HEAD 之前承诺 。
替换上次承诺的新承诺:
git commit --amend -m "message"
它将以新承诺取代最后一项承诺 。
其他回答
您可以以两种方式撤销您的 Git 承诺: 首先, 您可以使用git revert
,如果你想保留你的承诺历史:
git revert HEAD~3
git revert <hashcode of commit>
第二,你可以使用git reset
,它会删除你所有的承诺历史, 并带来你的头在你想要的地方。
git reset <hashcode of commit>
git reset HEAD~3
您也可以使用--hard
关键字,如果有的话,我只推荐它,直到它变得非常必要。
通常我并不想撤销一连串的承诺, 而是编辑早先的承诺,
我发现自己经常去修修过去的东西 以至于我写了剧本
以下是工作流程:
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 rebase --onto HEAD~1 HEAD
但如果你想放弃其中的 多项承诺,你确实说
- > b - > c - > > d - > 硕士
,然后您要放弃“ c” 承诺
git rebase --onto b c
这将使“ b” 成为“ d” 删除“ c” 的新基础
使用此命令( 在顶部的日志 1 中, 这是最新命令) 获取上次的 身份确认 :
git log
获取执行 ID (GUID) 并运行此命令 :
git revert <commit_id>
我通常首先会发现我最近所作所为的杂草:
git log
看起来是这样的:commit {long_hash}
复制此副本long_hash
并重置它(回到相同的文件/声明在承诺上):
git reset --hard {insert long_hash without braces}