-
Notifications
You must be signed in to change notification settings - Fork 25.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve hint for diverging branches. #1570
base: master
Are you sure you want to change the base?
Conversation
Welcome to GitGitGadgetHi @perk11, and welcome to GitGitGadget, the GitHub App to send patch series to the Git mailing list from GitHub Pull Requests. Please make sure that your Pull Request has a good description, as it will be used as cover letter. You can CC potential reviewers by adding a footer to the PR description with the following syntax:
Also, it is a good idea to review the commit messages one last time, as the Git project expects them in a quite specific form:
It is in general a good idea to await the automated test ("Checks") in this Pull Request before contributing the patches, e.g. to avoid trivial issues such as unportable code. Contributing the patchesBefore you can contribute the patches, your GitHub username needs to be added to the list of permitted users. Any already-permitted user can do that, by adding a comment to your PR of the form Both the person who commented An alternative is the channel
Once on the list of permitted usernames, you can contribute the patches to the Git mailing list by adding a PR comment If you want to see what email(s) would be sent for a After you submit, GitGitGadget will respond with another comment that contains the link to the cover letter mail in the Git mailing list archive. Please make sure to monitor the discussion in that thread and to address comments and suggestions (while the comments and suggestions will be mirrored into the PR by GitGitGadget, you will still want to reply via mail). If you do not want to subscribe to the Git mailing list just to be able to respond to a mail, you can download the mbox from the Git mailing list archive (click the curl -g --user "<EMailAddress>:<Password>" \
--url "imaps://imap.gmail.com/INBOX" -T /path/to/raw.txt To iterate on your change, i.e. send a revised patch or patch series, you will first want to (force-)push to the same branch. You probably also want to modify your Pull Request description (or title). It is a good idea to summarize the revision by adding something like this to the cover letter (read: by editing the first comment on the PR, i.e. the PR description):
To send a new iteration, just add another PR comment with the contents: Need help?New contributors who want advice are encouraged to join git-mentoring@googlegroups.com, where volunteers who regularly contribute to Git are willing to answer newbie questions, give advice, or otherwise provide mentoring to interested contributors. You must join in order to post or view messages, but anyone can join. You may also be able to find help in real time in the developer IRC channel, |
There are issues in commit 23fa109: |
23fa109
to
40aa49a
Compare
There are issues in commit 40aa49a: |
237f897
to
5044df2
Compare
/allow |
User perk11 is now allowed to use GitGitGadget. |
5044df2
to
123b22b
Compare
/preview |
Preview email sent as pull.1570.git.git.1693858078020.gitgitgadget@gmail.com |
Added a description of what the offered options will do and for pull also offered a 3rd option during a pull - a hard reset. This option should be helpful for the new users that accidentally committed into the wrong branch which is a scenario I saw very often. The resulting tooltip looks like this for pull: hint: Diverging branches can't be fast-forwarded. Consider the following options: hint: hint: To merge remote changes into your branch: hint: git merge --no-ff hint: hint: To apply your changes on top of remote changes: hint: git rebase hint: hint: To discard your local changes and apply the remote changes: hint: git reset --hard refs/remotes/upstream/branch-name hint: hint: Disable this message with "git config advice.diverging false" There is some danger because it's semi-destructive, but so are other options offered if user doesn't know the commands to revert back. Additionally, I think "To discard your local changes" wording describes the danger clearly enough. And for merge I improved the wording and added a description of what the commands do: hint: Diverging branches can't be fast-forwarded. hint: Consider the following options: hint: hint: To merge changes into your branch: hint: git merge --no-ff hint: hint: To apply your changes on top: hint: git rebase hint: hint: Disable this message with "git config advice.diverging false" Signed-off-by: Konstantin Pereiaslov <perk11@perk11.info>
123b22b
to
21bf8fb
Compare
/preview |
Preview email sent as pull.1570.git.git.1693858939372.gitgitgadget@gmail.com |
/preview |
Preview email sent as pull.1570.git.git.1693859432738.gitgitgadget@gmail.com |
/submit |
Submitted as pull.1570.git.git.1693861162353.gitgitgadget@gmail.com To fetch this version into
To fetch this version to local tag
|
On the Git mailing list, Junio C Hamano wrote (reply to this): "Konstantin Pereiaslov via GitGitGadget" <gitgitgadget@gmail.com>
writes:
> From: Konstantin Pereiaslov <perk11@perk11.info>
>
> Added a description of what the offered options will do and for pull
> also offered a 3rd option during a pull - a hard reset.
> This option should be helpful for the new users that accidentally
> committed into the wrong branch which is a scenario I saw very
> often.
cf. Documentation/SubmittingPatches:[[describe-changes]]
> The resulting tooltip looks like this for pull:
>
> hint: Diverging branches can't be fast-forwarded.
> Consider the following options:
We do not give "hint:" prefix to this line???
> hint:
> hint: To merge remote changes into your branch:
> hint: git merge --no-ff
> hint:
> hint: To apply your changes on top of remote changes:
> hint: git rebase
Hmph, "apply" -> "replay" perhaps?
> hint: To discard your local changes and apply the remote changes:
Here "apply" is definitely a misnomer. Nothing is applied; you just
discard your work and adopt (or "accept") the state of the remote as
a whole.
> hint: git reset --hard refs/remotes/upstream/branch-name
> hint:
> hint: Disable this message with "git config advice.diverging false"
OK.
Overall, "... looks like this" should be shown a bit indented so
that the example stands out from the text that explains the example.
> There is some danger because it's semi-destructive, but so are
> other options offered if user doesn't know the commands to
> revert back.
Sorry, but I do not quite understand what you want to say here.
> @@ -1112,8 +1126,10 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
>
> /* ff-only takes precedence over rebase */
> if (opt_ff && !strcmp(opt_ff, "--ff-only")) {
> - if (divergent)
> - die_ff_impossible();
> + if (divergent) {
> + const char* pull_branch_spec = get_pull_branch(repo, *refspecs);
In this codebase, asterisk sticks to the variable/function
identifier, not types.
But more importantly, what guarantees your recomputation using
'*refspecs' here will match the result of the logic that computed
'divergent', which certainly would have already known what commit we
tried to fast-forward our branch to, and where that commit came
from? We shouldn't be computing the same thing twice, and in
different ways; that is a sure way to introduce inconsistent
results.
> + die_ff_impossible_during_pull(pull_branch_spec);
> + }
> opt_rebase = REBASE_FALSE;
> }
> /* If no action specified and we can't fast forward, then warn. */
>
> base-commit: d814540bb75bbd2257f9a6bf59661a84fe8cf3cf
Thanks. |
On the Git mailing list, Konstantin Pereiaslov wrote (reply to this): Thank you, all good points. I will work on the wording
improvements based on your suggestions.
"Consider the following options:" should be on a new line and
get a "hint:" prefix, I will fix that.
As far as the danger to the user, I was talking about the fact that
the user doing "git reset --hard" is going to lose any uncommitted
work as well as any commits currently in the branch.
> "But more importantly, what guarantees your recomputation using
> '*refspecs' here will match the result of the logic that computed
> 'divergent', which certainly would have already known what commit we
> tried to fast-forward our branch to, and where that commit came
> from? We shouldn't be computing the same thing twice, and in
> different ways; that is a sure way to introduce inconsistent
> results.
This makes sens, I did it this way because I wanted to get a remote and
branch name, not just hash id and it was difficult to get this information.
I will try to rework it so that it shares the code with the logic that determines
the divergence status.
Any tips on what's the best way to do that would be highly appreciated.
On 9/5/23 18:20, Junio C Hamano wrote:
> "Konstantin Pereiaslov via GitGitGadget" <gitgitgadget@gmail.com>
> writes:
>
>> From: Konstantin Pereiaslov <perk11@perk11.info>
>>
>> Added a description of what the offered options will do and for pull
>> also offered a 3rd option during a pull - a hard reset.
>> This option should be helpful for the new users that accidentally
>> committed into the wrong branch which is a scenario I saw very
>> often.
> cf. Documentation/SubmittingPatches:[[describe-changes]]
>
>> The resulting tooltip looks like this for pull:
>>
>> hint: Diverging branches can't be fast-forwarded.
>> Consider the following options:
> We do not give "hint:" prefix to this line???
>
>> hint:
>> hint: To merge remote changes into your branch:
>> hint: git merge --no-ff
>> hint:
>> hint: To apply your changes on top of remote changes:
>> hint: git rebase
> Hmph, "apply" -> "replay" perhaps?
>
>> hint: To discard your local changes and apply the remote changes:
> Here "apply" is definitely a misnomer. Nothing is applied; you just
> discard your work and adopt (or "accept") the state of the remote as
> a whole.
>
>> hint: git reset --hard refs/remotes/upstream/branch-name
>> hint:
>> hint: Disable this message with "git config advice.diverging false"
> OK.
>
> Overall, "... looks like this" should be shown a bit indented so
> that the example stands out from the text that explains the example.
>
>> There is some danger because it's semi-destructive, but so are
>> other options offered if user doesn't know the commands to
>> revert back.
> Sorry, but I do not quite understand what you want to say here.
>
>> @@ -1112,8 +1126,10 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
>> >> /* ff-only takes precedence over rebase */
>> if (opt_ff && !strcmp(opt_ff, "--ff-only")) {
>> - if (divergent)
>> - die_ff_impossible();
>> + if (divergent) {
>> + const char* pull_branch_spec = get_pull_branch(repo, *refspecs);
> In this codebase, asterisk sticks to the variable/function
> identifier, not types.
>
> But more importantly, what guarantees your recomputation using
> '*refspecs' here will match the result of the logic that computed
> 'divergent', which certainly would have already known what commit we
> tried to fast-forward our branch to, and where that commit came
> from? We shouldn't be computing the same thing twice, and in
> different ways; that is a sure way to introduce inconsistent
> results.
>
>> + die_ff_impossible_during_pull(pull_branch_spec);
>> + }
>> opt_rebase = REBASE_FALSE;
>> }
>> /* If no action specified and we can't fast forward, then warn. */
>>
>> base-commit: d814540bb75bbd2257f9a6bf59661a84fe8cf3cf
> Thanks. |
On the Git mailing list, Konstantin Pereiaslov wrote (reply to this): Thank you, all good points. I will work on the wording
improvements based on your suggestions.
"Consider the following options:" should be on a new line and
get a "hint:" prefix, I will fix that.
As far as the danger to the user, I was talking about the fact that
the user doing "git reset --hard" is going to lose any uncommitted
work as well as any commits currently in the branch.
> "But more importantly, what guarantees your recomputation using
> '*refspecs' here will match the result of the logic that computed
> 'divergent', which certainly would have already known what commit we
> tried to fast-forward our branch to, and where that commit came
> from? We shouldn't be computing the same thing twice, and in
> different ways; that is a sure way to introduce inconsistent
> results.
This makes sens, I did it this way because I wanted to get a remote and
branch name, not just hash id and it was difficult to get this information.
I will try to rework it so that it shares the code with the logic that determines
the divergence status.
Any tips on what's the best way to do that would be highly appreciated.
On 9/5/23 18:20, Junio C Hamano wrote:
> "Konstantin Pereiaslov via GitGitGadget" <gitgitgadget@gmail.com>
> writes:
>
>> From: Konstantin Pereiaslov <perk11@perk11.info>
>>
>> Added a description of what the offered options will do and for pull
>> also offered a 3rd option during a pull - a hard reset.
>> This option should be helpful for the new users that accidentally
>> committed into the wrong branch which is a scenario I saw very
>> often.
> cf. Documentation/SubmittingPatches:[[describe-changes]]
>
>> The resulting tooltip looks like this for pull:
>>
>> hint: Diverging branches can't be fast-forwarded.
>> Consider the following options:
> We do not give "hint:" prefix to this line???
>
>> hint:
>> hint: To merge remote changes into your branch:
>> hint: git merge --no-ff
>> hint:
>> hint: To apply your changes on top of remote changes:
>> hint: git rebase
> Hmph, "apply" -> "replay" perhaps?
>
>> hint: To discard your local changes and apply the remote changes:
> Here "apply" is definitely a misnomer. Nothing is applied; you just
> discard your work and adopt (or "accept") the state of the remote as
> a whole.
>
>> hint: git reset --hard refs/remotes/upstream/branch-name
>> hint:
>> hint: Disable this message with "git config advice.diverging false"
> OK.
>
> Overall, "... looks like this" should be shown a bit indented so
> that the example stands out from the text that explains the example.
>
>> There is some danger because it's semi-destructive, but so are
>> other options offered if user doesn't know the commands to
>> revert back.
> Sorry, but I do not quite understand what you want to say here.
>
>> @@ -1112,8 +1126,10 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
>> >> /* ff-only takes precedence over rebase */
>> if (opt_ff && !strcmp(opt_ff, "--ff-only")) {
>> - if (divergent)
>> - die_ff_impossible();
>> + if (divergent) {
>> + const char* pull_branch_spec = get_pull_branch(repo, *refspecs);
> In this codebase, asterisk sticks to the variable/function
> identifier, not types.
>
> But more importantly, what guarantees your recomputation using
> '*refspecs' here will match the result of the logic that computed
> 'divergent', which certainly would have already known what commit we
> tried to fast-forward our branch to, and where that commit came
> from? We shouldn't be computing the same thing twice, and in
> different ways; that is a sure way to introduce inconsistent
> results.
>
>> + die_ff_impossible_during_pull(pull_branch_spec);
>> + }
>> opt_rebase = REBASE_FALSE;
>> }
>> /* If no action specified and we can't fast forward, then warn. */
>>
>> base-commit: d814540bb75bbd2257f9a6bf59661a84fe8cf3cf
> Thanks.
> |
I have seen a lot of developers not know what to do when they try
to do a git pull on a master branch with the intention of updating
that branch to the latest version, but see an error about branches
diverging because they accidentally committed their changes to
that branch. They then spend their time resolving conflicts and
still not getting the intended result. The suggestion to do a hard
reset should be something that helps in this situation.
I'm not sure if a new config option needs to be created as
technically these are two different advice now.
I'm also not sure if "refs/remotes" part of the refspec is necessary,
that is what I found the functions in pull.c are returning.
I think "upstream/branch-name" should be the same thing, but kept it
as is ( git reset --hard refs/remotes/upstream/branch-name) for now.
Please feel free to chime in.