我无意间把错误的档案 写错给Git 基特,但还没有将承诺推进到服务器上。
我如何解除那些承诺?当地当地仓库?
我无意间把错误的档案 写错给Git 基特,但还没有将承诺推进到服务器上。
我如何解除那些承诺?当地当地仓库?
当前回答
reset --soft
或reset --hard
?@Kyralessa的回答:
如果您不确定该使用什么--soft
(我用这个公约来纪念它)s. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
如果您选择了--hard
你会犯错,你会犯错输 输之前没有的更改。如果您选择--soft
犯错后,您也可以得出相同的结果。--hard
通过应用附加命令
git reset HEAD file.html
git checkout -- file.html
echo "some changes..." > file.html
git add file.html
git commit -m "wrong commit"
# I need to reset
git reset --hard HEAD~1 (cancel changes)
# OR
git reset --soft HEAD~1 # Back to staging
git reset HEAD file.html # back to working directory
git checkout -- file.html # cancel changes
感谢@Kyralessa。
其他回答
撤销最后一次承诺的最简单方式是
git reset HEAD^
这将带来项目状态 之前,您已经做出承诺。
撤销上次承诺 :
git reset --soft HEAD^ or git reset --soft HEAD~
这将撤销最后一项承诺 。
给--soft
意思是重置为中位 。
HEAD~ or HEAD^
意思是移动以在 HEAD 之前承诺 。
替换上次承诺的新承诺:
git commit --amend -m "message"
它将以新承诺取代最后一项承诺 。
我验证了所提议的有效方法,这里就是使用这一方法的一个具体例子:
如果您想要永久撤销/取消您的最后一项承诺(等等, 一个一个一个, 尽可能多) , 有三个步骤 :
1: 获取您想要到达的承诺的 id = SHA, 当然
$ git log
2: 删除您先前的承诺
$ git reset --hard 'your SHA'
3: 将新的本地历史强制在您的原籍 GitHub 与-f
选项( 将从 GitHub 历史中删除最后的磁轨)
$ git push origin master -f
$ git log
最后一次承诺取消
commit e305d21bdcdc51d623faec631ced72645cca9131 (HEAD -> master, origin/master, origin/HEAD)
Author: Christophe <blabla@bla.com>
Date: Thu Jul 30 03:42:26 2020 +0200
U2_30 S45; updating files package.json & yarn.lock for GitHub Web Page from docs/CV_Portfolio...
现在就向总部提交我们想要的文件
commit 36212a48b0123456789e01a6c174103be9a11e61
Author: Christophe <blabla@bla.com>
Date: Thu Jul 30 02:38:01 2020 +0200
First commit, new title
$ git reset --hard 36212a4
HEAD is now at 36212a4 First commit, new title
$ git log
commit 36212a48b0123456789e01a6c174103be9a11e61 (HEAD -> master)
Author: Christophe <blabla@bla.com>
Date: Thu Jul 30 02:38:01 2020 +0200
First commit, new title
$ git status
On branch master
Your branch is behind 'origin/master' by 1 commit, and can be fast-forwarded.
(use "git pull" to update your local branch)
nothing to commit, working tree clean
$ git push origin master -f
Total 0 (delta 0), reused 0 (delta 0), pack-reused 0
To https://github.com/ GitUser bla bla/React-Apps.git
+ e305d21...36212a4 master -> master (forced update)
$ git status
On branch master
Your branch is up to date with 'origin/master'.
nothing to commit, working tree clean
如果您想要删除错误的文件, 您应该做
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