我无意间把错误的档案 写错给Git 基特,但还没有将承诺推进到服务器上。
我如何解除那些承诺?当地当地仓库?
我无意间把错误的档案 写错给Git 基特,但还没有将承诺推进到服务器上。
我如何解除那些承诺?当地当地仓库?
当前回答
另一种方式:
检查您想要返回的分支, 然后将本地工作副本重置到您想要在远程服务器上成为最新一份的承诺( 它将在离别后进行的一切) 。 要做到这一点, 请在 SupportTree I右键点击并选中的“ 重置 BranchNAME 以进行此承诺 ” 。
然后导航到仓库的本地目录并运行此命令 :
git -c diff.mnemonicprefix=false -c core.quotepath=false push -v -f --tags REPOSITORY_NAME BRANCHNAME:BRANCHNAME
这将删除您本地仓库中当前一个后的所有承诺, 但只删除该分支 。
其他回答
假设您在本地犯下错误, 并将其推到远程仓库。 您可以解开这两个命令的混乱 :
首先,我们需要纠正我们的地方储存库,回到我们所希望的承诺上来:
git reset --hard <previous good commit id where you want the local repository to go>
现在,我们通过使用此命令,在远程仓库大力推动这项良好承诺:
git push --force-with-lease
强制选项的“ 租赁” 版本将防止意外删除您不知道的新承诺( 即上次拉动后来自其它来源 ) 。
通常我并不想撤销一连串的承诺, 而是编辑早先的承诺,
我发现自己经常去修修过去的东西 以至于我写了剧本
以下是工作流程:
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 revert <commit-id>
.
为了得到身份证明 只需使用git log
.
类型类型类型git log
并发现最后的散列代码,然后输入:
git reset <the previous co>
git reset --soft HEAD~1
git status
在分母上
您的分行在“ 来源/ 主机” 前面 1 个承诺 。
(使用“ little push” 发布您的本地承诺)拟承诺的修改:
(使用“ git reconful -- paged...” 到 unstage) 新文件 : file1
git log --oneline --graph
- 90f8bb1 (HEAD - > 主人) 第二次承诺\
- 7083e29 初始仓库承诺