我无意间把错误的档案 写错给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
其他回答
我想撤销我们共享存储库中最新的五个承诺。 我查了我想回溯到的订正代号 。 然后我输入了下面的内容 。
prompt> git reset --hard 5a7404742c85
HEAD is now at 5a74047 Added one more page to catalogue
prompt> git push origin master --force
Total 0 (delta 0), reused 0 (delta 0)
remote: bb/acl: neoneye is allowed. accepted payload.
To git@bitbucket.org:thecompany/prometheus.git
+ 09a6480...5a74047 master -> master (forced update)
prompt>
使用 git- gui (或类似) 执行git commit --amend
。从 GUI 中,您可以从承诺中添加或删除单个文件。您也可以修改承诺信件。
仅将分支重新设置为上一个位置(例如,使用gitk
或git rebase
) 。然后从保存的副本中重新应用您的更改。在您本地仓库的垃圾回收收集后,它会像没有发生不想要的操作一样。要用一个命令来完成所有这些,请使用git reset HEAD~1
.
警告单词: 粗心使用git reset
我建议基特新手们尽可能避免这样做。
表演a逆向樱桃摘 (git- rever 反转)来撤销更改。
如果你还没有在你的分支上做其他的修改, 你可以简单地做。 。 。
git revert --no-edit HEAD
然后将更新的分支推至共享仓库 。
承诺历史将分别显示两个承诺.
备注:如果有其他人在为分支工作,您不想这样做。
git push --delete (branch_name) ## remove public version of branch
清理你的分行 在当地,然后冲...
git push origin (branch_name)
通常情况下,你可能不必担心你的私人部门 将历史变成原始历史。只是催促后续承诺(见上文“如何撤销公共承诺”),然后,做一个壁球- 合并隐藏历史。
删除已被推到 Github 的错误行为
git push origin +(previous good commit id):(branch name)
请指定您想要在 Github 重置的最后一个好承诺代号 。
例如,如果最近的承诺 ID 错误, 请用分支名称在 Git 命令上方指定前一个承诺 ID 。
您可以使用git log
第一运行 :
git reflog
这将显示您在存储库中实施的所有可能的动作, 例如, 承诺、 合并、 调用等 。
那么,请:
git reset --hard ActionIdFromRefLog
我拿到了身份证明bitbucket
并随后:
git checkout commitID .
示例:
git checkout 7991072 .
它又把它恢复到那个承诺的工作副本上。