I am new to GIT and I am trying to wrap my head around its concepts. As a result I have some basic questions. Please pardon my naivety. I searched the internet but ended up getting more confused. Here are my questions:-
$ 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 themaster branch
(first output above) why does it also show commits from myfeature
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 becausegit
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 made2
commits
onfeature
branch and merged them toremote 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 localmaster
branch, but how do I get rid of them from the remote master branch since they were already merged to master ? Is it thatreset
is used for local commits whilerevert
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.
- Do, I need to first
Since I am just getting started with git it may be possible that I have asked a wrong question. Either way please excuse my naivety. Any help is appreciated.