How do I enforce the Git rule "Do not reinstall published commits"?

The Pro Git book strongly recommends following this rule:

Do not overload commits that exist outside of your repository.

Is there an easy way to make sure you don’t break the rule? For example, the Git command set?

I mean, if you are not sure if you published all or part of your latest commits or not (maybe you are participating in several projects that use Git, and you just switched to one of your projects) .

Or maybe this question is just nonsense? I am not a git expert.

+5
source share
1 answer

You can get a list of "unpushed" commits in your local repository by comparing the current branch with the upstream branch. For example, something like:

$ git status On branch master Your branch is ahead of 'origin/master' by 1 commit. (use "git push" to publish your local commits) nothing to commit, working directory clean 

This tells us that we have one fixation that we have not moved up. We can use git log to list these commits:

 $ git log --oneline origin/master..master bc9dacf added another file 

So, there is a list of unpublished commits that we could repack willingly, without affecting a single employee. As long as you limit yourself to them you are in good shape.

Of course, part of your question was about automating this behavior. There is a pre-rebase hook that is called before the redirect operation, which can be used to provide this, but I think I will leave this as an exercise for the reader. I am not sure if this is a big problem in practice.

If the upstream project you are working with has a workflow based on GitHub or Gerrit submission requests or something similar, you need to worry less: because you never push the shared repository, your changes will simply be discarded if you succeed reinstall your local repository in a way that is incompatible with the state of the source code.

+2
source

All Articles