我无意间把错误的档案 写错给Git 基特,但还没有将承诺推进到服务器上。
我如何解除那些承诺?当地当地仓库?
我无意间把错误的档案 写错给Git 基特,但还没有将承诺推进到服务器上。
我如何解除那些承诺?当地当地仓库?
当前回答
“ 将工作树重置为最后一次承诺 ”
git reset --hard HEAD^
"清除工作树上的未知文件"
git clean
见 -Git 快速参考
注:此命令将删除您上一个任务所以要谨慎使用!git reset --hard
更安全。
其他回答
我拿到了身份证明bitbucket
并随后:
git checkout commitID .
示例:
git checkout 7991072 .
它又把它恢复到那个承诺的工作副本上。
git reset --soft HEAD~1
软性 : 这将只从本地端删除承诺, 并保留文件所做的更改 。
git reset --hard HEAD~1
git push origin master
硬性 : 这将从本地和远程删除承诺, 并删除文件中所做的更改 。
如果您想要删除错误的文件, 您应该做
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 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