0

I used force push to amend a commit message on my branch B. I'm working alone on this branch, then I requested a PR to master A.

Will there be a problem after the PR is accepted?

according to this answer, people that have pulled from my branch will get an error. But nobody did pull from my branch. But after PR merge, my branch along with the amended commit will be in master. So will developers that have pulled/will pull from master get any error?

this answer doesn't say if there will be any errors for other developers fetching from master after the PR merge

rohitt
  • 1,124
  • 6
  • 18
  • If you've put up a PR, and adjust the PR, it's all fine as long as it's still a PR. (This is somewhat specific to GitHub.) Dietrich Epp's answer about how those who already grabbed your earlier commits is good, though the claim that they'd get an *error* is too strong; but the thing is, you've presupposed here that nobody grabbed your earlier commits. So this becomes irrelevant. It's like saying that everyone who ate the poisoned peanuts will die: if we know for sure that *nobody* ate the poisoned peanuts, that statement may be true, but nobody will die and there is nothing to worry about. – torek Jul 24 '21 at 08:13
  • Note that base Git *does not have pull requests*. Each provider (GitHub, GitLab, Bitbucket, etc) do their own thing to add on something like pull requests (GitLab do not even call them pull requests) and hence the situation with each provider is potentially different. If you only care about GitHub, say so, and keep the [tag:github] tag. – torek Jul 24 '21 at 08:14
  • It is a PR and fortunately about adding a new file. So nobody grabbed my commits. I just don't want to cause unnecessary trouble to other developers or maintainers after the PR merge. – rohitt Jul 24 '21 at 08:18

1 Answers1

1

The issue with editing commits and force pushing is that as far as git is concerned the unedited and edited commits are unrelated. So if someone pulls both the original version and the edited version of the commits git will try to merge them and make a mess.

On the other hand if they only pull the edited version everything is fine.

So force pushing a branch that is being used for collaboration or for end users to download is generally a bad idea.

On the other hand force pushing a pull request branch is generally ok and is comonly done to clean things up in response to feedback. Only the final version of the pull request is likely to get merged into branches that actually matter.

plugwash
  • 9,724
  • 2
  • 38
  • 51
  • Thankyou. Will other developers ever find out my force push after merge (except by viewing my PR)? – rohitt Jul 24 '21 at 08:41
  • 1
    People following the main branch will only ever see the final version of the commits, not the ones you pushed originally and later overwrote with the force push. – plugwash Jul 24 '21 at 08:57