简体   繁体   中英

If I delete a branch without merging, what happens? Can I do that to undo my changes?

Imagine you just created a new branch, added some commits and noticed you messed up. Can you now just delete the (not merged) branch to undo your changes?

Talking about the regular Github page.

Thanks!

It is gone from origin , meaning the main version of your repo, meaning the version that is on GitHub.com. However, someone might have had time to clone the repo and checked out that branch in their clone. Then that branch exist in the clone regardless what you do to origin if that is important. Including your own clone.

(Technically something else can be origin but I am assuming here that you do not have some advanced set up. What I assume would be the case if you have created your repo on GitHub.com and not changed any advanced settings.)

If you are using branches, then you should be aware of the branching pattern you are using:) Most people use some sort of trunk branch (master/main/develop) and feature or story branches. Whether you use PRs to merge or just merge and push locally is probably irrelevant here.

On that basis, code on a branch makes no difference to the trunk itself and whether you choose to delete the branch or just leave it on github and allow to wither is of little difference - there are pros to leaving the code there. Whatever, if somebody else has cloned the repo, they will have a copy and might have started to use it - thus the distributed nature of git.

There are two potential places I can think of where there may be issues:

  1. The branch contains something it should not - such as somebody else's copyright code. In that situation, you definitely want to delete it ASAP.
  2. You accidentally push a big file to the repo. This will not cause logical problems but will usually slow down cloning. Again best to delete the branch.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM