¿Commits destructivos de Git?

I'm starting to learn Git, which, so far, is great. I'm just confused on one area, this could just be a misunderstanding.

Suppose that John is working in the "john" directory and Bob is working in the "bob" directory.

If John's code isn't the final item we desire for the "john" directory and Bob pulls from the dev branch, Bob will get all of John's "bad" code, correct?

So, Bob applies a simple fix to the "bob" directory and pushes to the production branch. Doesn't John's bad code in the "john" directory sneak onto the production branch through Bob's push?

Does this even happen? How is this avoided?

Gracias a todos!

preguntado el 03 de mayo de 12 a las 20:05

They are on the same branch "development" working in two different directories. It is possible that, in this theoretical situation, that Bob and John messed up by not splitting into their own branches in the first place... -

2 Respuestas

There's a distinction between pushing dev -> production and committing a fix to the production branch directly. The latter is safe for bob.

The only way to know code is safe is to test it before pushing it. This could be a QA team, regression/unit tests, etc.

contestado el 03 de mayo de 12 a las 20:05

So, if Bob needs to do a hot fix, he would check out the production branch, commit the fix to the branch, then push the production branch back without even touching the dev branch? What if Bob had been building his stuff on the dev branch like John. Would it be possible for Bob to push his project (as opposed to a hot fix) to the production branch without John's code coming with it? - Oliver I

@Coder_Man - yes but what you are talking about is re-writing history which is NOT a good idea on a remote repo. Best to use git-revert. You can force git to overwrite the history using -f but without that switch git tells you, "remote is newer and you must pull first" - flumpb

You usually will not commit "broken code" into develop o el master (that are the common names). The develop branch is usually for code "that should work", master is for "stable code" (something like trunk in svn). If you want to create something new, create a new branch for it, for example feature/myFeature. Now everybody knows, that this code may, or may not be complete and will usually avoid to merge it into their own branch. Once you are done ("it should work"), merge it back into develop.

However, even if you scenario happens, git will recognize, that this bad code is already part of develop, and will not apply it again.

contestado el 03 de mayo de 12 a las 20:05

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.