我想重置我的本地分支到提交as288sa
。 提交存储在远程存储库和我的本地存储库中。 我想使用--hard
标志重置。git reset --hard to commit does not work - Tip is HEAD is behind
git reset --hard as288sa
Checking out files HEAD is now at as288sa
然后我想add
和commit
的reset
和push
是提交到远程仓库。
git add -A
git commit -m "reseted hard"
On branch myBranch nothing to commit, working tree clean
git push origin myBranch
rejected error: failed to push some refs to [email protected] Updates were rejected because the tip of you current branch is behind its counterpart. Integrate the remote changes (e.g. git pull) before pushing changes
所以我做了一个git pull
,然后git add -A
和git commit
以及一个git push
,并试图再git reset --hard as288sa
。 我再次收到相同的错误消息。
发生了什么事?
为什么我不想用'--hard'标志''重置'commit'?我知道这会删除提交前提交的所有'commit',我将它重置为。但是,如果我不在乎丢失他们?那对其他人会有什么问题? – Stophface
在任何给定的时间,当从远程git拉取数据时,假定分支的本地引用与同一分支的远程引用相同,或者可以从远程引用(即其祖先)访问。如果您向后移动分支的远程参考,然后可能开始将其沿分支路径向下移动,那么该回购的其他用户将会发现该假设被破坏。他们可以恢复,但是如果他们在分支上做了其他更改,他们必须重新设置这些更改。如果回购是共享的,那么通常会以糟糕的形式删除已发布的提交或将已发布的头部“向后移动” –