Git-如何删除远程主分支上的提交

我是GIT的新手,正在尝试围绕GIT的概念。结果,我有一些基本问题。请原谅我的天真。我搜索了互联网,但最终变得更加困惑。这是我的问题:

$ git log -n 10 --oneline
170daa2 (HEAD -> master, origin/master, origin/HEAD) Revert "Undo Pull request from feature branch test"
e3f0714 Revert pull request test This reverts commit c6b3b1a
c6b3b1a Revert commit
b72e92e Undo Pull request from feature branch test
3077d10 (origin/feature/test1, feature/test1) First commit
1ba77e8 Updated test1
8fceee2 Revert Commit 1
ecddd63 Test for remote status
6c5a094 Cherry Pick 1
3b66732 Fixed conflict

$ git log -n 6 --oneline feature/test1
3077d10 (origin/feature/test1, feature/test1) First commit
1ba77e8 Updated test1
8fceee2 Revert Commit 1
ecddd63 Test for remote status
6c5a094 Cherry Pick 1
3b66732 Fixed conflict
  • As seen from above, when I do git log while being on the master branch (first output above) why does it also show commits from my feature branch (feature/test1) along with the ones in my master ? When I explicitly specify the branch in the git log it then shows the commits pertaining to that branch only, right ? Is it because git will show all commits (irrespective of any branch) combined together in chronological order ? Can anyone please explain.

  • How to delete commits on a remote branch ? -
    Suppose I have made 2 commits on feature branch and merged them to remote master via a pull request.
    Now, I realize those are bad commits and I want to cleanup and rollback to the state where my remote master (and the local master) branches were before the pull request was approved. I know I could use: git reset --hard HEAD~2
    to get rid of these 2 commits on the local master branch, but how do I get rid of them from the remote master branch since they were already merged to master ? Is it that reset is used for local commits while revert is used for remote commits ? What is the difference between these 2 commands ? and how do I solve my question -

    • Do, I need to first reset master locally and then "force push" this state to remote master by running: git push origin +master ? Is this a correct approach ? OR
    • Do I use git revert -m 1 <commit-hash> to undo commits from remote branch with the caveat that the revert will rollback and make a new commit. Is there any way to rollback on both remote and local master branch without making a new commit ? Please suggest the best approach.

由于我刚开始使用git,所以我可能会问错一个问题。无论哪种方式,请原谅我的天真。 任何帮助表示赞赏。