After git reset how to push to master?

huangapple go评论47阅读模式
英文:

After git reset <commitid> how to push to master?

问题

I made a series of mistakes and I want to revert 4 commits back. I did this:
git reset <commitId>
This caused me to have a number of changes not staged for commit, and a number of untracked files.

The untracked files are the new files for the unwanted commits and I manually removed the files using
rm <file>
I then ran the project and everything is to my liking.

I now think I should do a
git commit -m 'reverting back to XXXXX'
git push
Does this sound about right? Just want to be sure I am doing this right.

Edit: I think as others of told me, this doesn't quite make sense. I believe I had actually confused reset versus revert. I checked the correct answer for my situation. Thanks!

英文:

I made a series of mistakes and I want to revert 4 commits back. I did this:

git reset &lt;commitId&gt; 

This caused me to have a number of changes not staged for commit, and a number of untracked files.

The untracked files are the new files for the unwanted commits and I manually removed the files using

rm &lt;file&gt;

I then ran the project and everything is to my liking.

I now think I should do a

git commit -m &#39;reverting back to XXXXX&#39; 
git push

Does this sound about right? Just want to be sure I am doing this right.

Edit: I think as others of told me, this doesn't quite make sense. I believe I had actually confused reset versus revert. I checked the correct answer for my situation. Thanks!

答案1

得分: 1

在执行重置时,通常不需要实际进行任何提交,因为它的作用是将分支重置到一个旧的提交点。

如果你想要执行真正的重置而不重新提交任何内容,你应该执行 git reset <old-commit> --hard

之后你需要进行强制推送。git push --force-with-lease
with-lease 部分会在其他人对该分支进行更改时导致强制推送失败。
强制推送实际上会更改远程分支位置,而不会检查新位置是否是其当前位置的后代。

英文:

When doing a reset you normally don't have to actually do any commits since what it does is to reset the branch to point to an old commit.

If you want to do a true reset without re-committing anything you should do a git reset &lt;old-commit&gt; --hard

Afterwards you need to do a force push. git push --force-with-lease.
the with-lease part makes the force push fail if somebody else have made changes to the branch.
Pushing with force basically changes the remote branch location without checking that the new location is a descendant of its current location.

huangapple
  • 本文由 发表于 2023年6月15日 07:34:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/76478209.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定