我无意间把错误的档案 写错给Git 基特,但还没有将承诺推进到服务器上。
我如何解除那些承诺?当地当地仓库?
我无意间把错误的档案 写错给Git 基特,但还没有将承诺推进到服务器上。
我如何解除那些承诺?当地当地仓库?
当前回答
头:
在重置承诺之前, 我们应该知道关于 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
以下是图形表达式 :
其他回答
如果您想要删除错误的文件, 您应该做
git reset --soft <your_last_good_commit_hash_here>
来,如果你来git status
中,您会看到中转区的文件。您可以选择错误的文件,然后从中转区取下来。
喜欢下面。
git reset wrongFile1 wrongFile2 wrongFile3
您现在可以添加您需要按键的文件,
git add goodFile1 goodFile2
提交提交它们
git commit -v
或git commit -am "Message"
推,推,推,推,推,推,推,推,推,推,推,推,推,推,推,推,推,推,推,推,推,推,推,推,推,推,推,推,推,推,推,推,推,推,推,推,推
git push origin master
但是,如果您不关心已更改的文件, 您可以硬重置到先前的良好承诺, 并将所有文件都推到服务器 。
由
git reset --hard <your_last_good_commit_hash_here>
git push origin master
如果您已经向服务器发布错误的文件, 您可以使用--force
挂号以向服务器推动并编辑历史。
git push --force origin master
恢复和放弃承诺是最好的,如果你想在向公共部门等提出补丁时保持历史清洁有用的话。
如果你必须放下最上层的承诺, 那么以下的单行帮助
git rebase --onto HEAD~1 HEAD
但如果你想放弃其中的 多项承诺,你确实说
- > b - > c - > > d - > 硕士
,然后您要放弃“ c” 承诺
git rebase --onto b c
这将使“ b” 成为“ d” 删除“ c” 的新基础
通常我并不想撤销一连串的承诺, 而是编辑早先的承诺,
我发现自己经常去修修过去的东西 以至于我写了剧本
以下是工作流程:
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- 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)
通常情况下,你可能不必担心你的私人部门 将历史变成原始历史。只是催促后续承诺(见上文“如何撤销公共承诺”),然后,做一个壁球- 合并隐藏历史。
如何撤销最后的 Git 承诺 ?
为了让一切恢复到上次承诺之前的状态 我们需要重置在总部总部之前的承诺
如果你不想保留你所做的改变:
git reset --hard HEAD^
如果您想要保留您的更改 :
git reset --soft HEAD^
现在检查您的 git 日志。 它会显示我们上次的承诺已被删除 。