我无意间把错误的档案 写错给Git 基特,但还没有将承诺推进到服务器上。
我如何解除那些承诺?当地当地仓库?
我无意间把错误的档案 写错给Git 基特,但还没有将承诺推进到服务器上。
我如何解除那些承诺?当地当地仓库?
当前回答
git reset --soft HEAD~1
重置将会将您当前的 HEAD 分支倒带到指定的修订版 。
Note排--soft
旗帜 : 这样可以确保未撤销修改中的更改被保存。 在运行命令后, 您会发现这些更改是您工作副本中未承诺的本地修改 。
如果您不想保留这些修改,只需使用--hard
。确保只在确定不再需要这些更改时才这样做。
git reset --hard HEAD~1
撤消多个提交文件
git reset --hard 0ad5a7a6
但是,记住,使用重置命令可以解除所有在你返回后的承诺:
其他回答
这将添加一个新的承诺, 删除所添加的文件 。
git rm yourfiles/*.class
git commit -a -m "deleted all class files in folder 'yourfiles'"
或者您可以重写历史来撤销最后一项承诺 。
警告警告警告警告:此命令将永久删除对《京都议定书》的修改.java
您承诺的文件( 和任何其他文件) -- 从工作目录中删除全部修改 :
git reset --hard HEAD~1
缩略hard reset
至HEAD-1
您的工作副本将在您错误犯罪之前设定为犯罪状态 。
使用使用源树树(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
在我的情况中,我承诺并推向错误的分支, 所以我想要的是把全部的改变都收回来, 这样我就可以把它们投向一个新的正确的分支, 所以我做了这个:
在您承诺和推动的同一分支上, 如果您输入“ gitt status” 键入“ git status” 状态, 您将不会看到任何新事物, 因为您承诺和推动, 现在键入 :
git reset --soft HEAD~1
这将将您所有的更改( 文件) 重新回到舞台区域, 现在把它们重新回到工作目录( 非阶段) 中, 您只要输入 :
git reset FILE
“ 文件” 是您想要再次承诺的文件 。 现在, FILE 应该在工作目录中, 包含您所做的全部更改 。 现在您可以更改为您想要的分支, 并对该分支进行更改 。 当然, 您承诺的初始分支仍然有所有更改, 但对于我来说, 如果不是您的话, 您可以寻找恢复该分支承诺的方法 。
如果您想要删除错误的文件, 您应该做
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