![]() $ git reset -hard HEAD^ # remove the last commitĪt this point you are done if you are working alone.Ģ - Fix your teammate's local repositories Here is a simple approach in up to 4 steps:Ġ - Advise the team you are going to fix the repositoryĬonnect with the team and let them know of the upcoming changes.Īssuming your target branch is master: $ git checkout master # move to the target branch If they never pulled the bad commit, then this whole process won't affect them, and they can pull as normal. If they have pulled the bad commit, and committed on top of it, then they will have to reset, and then git cherry-pick the good commits that they want to create, effectively re-creating the whole branch without the bad commit. They will manually have to reset to a commit before the changed history, and then pull again. Next time anyone tries to pull from your repository, (if they've already pulled the bad commit), the pull will fail. You just have to make sure to reset to appropriate commits, before the new history split off from the old.Įdit: apparently you don't need to go to all this hassle on github, as you can force-push a reset branch. This process will also work with any other history changes (e.g. You can now go to the settings page and change the Main branch back to master. Now go to Bitbucket, and you should see the history that you want. ![]() Git push origin master # re-upload master to bitbucket Git reset master_temp # reset master to master_temp (removing the bad commit) git push origin :master # delete the original master branch from Bitbucket On Bitbucket, go to the repository settings, and change the "Main branch" to master_temp (on Github, change the "Default branch"). Git push origin master_temp # push the new master to Bitbucket Git reset HEAD^ # undo the bad commit on master_temp So you need to create a new branch, and make that the main branch: # on master: However, bitbucket and github and similar sites usually require there to be a main branch (presumably because it's easier than writing more code to handle the event that a repository has no branches - not sure). In git generally, the master branch is not special - it's just a convention. ![]() If you're trying to change the master branch Git push origin branch_name # push the branch back up again, without the last commit Git push origin :branch_name # delete the branch from bitbucket If you're trying to change a non-master branch: git reset HEAD^ # remove the last commit from the branch history If you are not working with others (or are happy to cause them significant annoyance), then it is possible to remove commits from bitbucket branches.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |