git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Geoffrey De Smet <ge0ffrey.spam@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: git reset respect remote repo (make git idiot proof)
Date: Thu, 04 Oct 2012 20:11:51 -0700	[thread overview]
Message-ID: <7vsj9tvci0.fsf@alter.siamese.dyndns.org> (raw)
In-Reply-To: <k4jj5n$72b$1@ger.gmane.org> (Geoffrey De Smet's message of "Thu, 04 Oct 2012 10:59:36 +0200")

Geoffrey De Smet <ge0ffrey.spam@gmail.com> writes:

> Op 03-10-12 18:40, Phil Hord schreef:
>> But I feel your pain.  I think the solution lies in relegating 'reset'
>> to the plumbing or the power-user realm of commands since I feel it is
>> quite overloaded and sometimes dangerous.  There was a thread some
>> months back heading in this direction, but I failed to keep it going.
>>
>>      http://comments.gmane.org/gmane.comp.version-control.git/185825
>
> I personally use git reset a lot:
> - Try an experiment
> - Commit a few commits as the experiment progresses
> - figure out that the experiment is a dead end
> - git reset all those _local_ commits
>
> The point is: they are local commits, so no harm done.
> But there's nothing preventing me from resetting pushed commits too,
> which would mean harm.

Even if you reset your local branch beyond the point you pushed out,
no harm is caused, as "git push" will catch that mistake, e.g.

	: on 'master' that integrates with 'master' at remote
	$ git reset --hard HEAD~4
        : work work work and commit commit commit
        $ git push origin master
        ... will result in refusal due to non-fast-forward

And then you can recover from it easily; one workflow may go like
this:

	: update refs/remotes/origin/master, among other things
	$ git fetch origin
        : recover the "work work ... commit commit" part
        $ git rebase origin/master

Another thing we could think about doing is to warn at the point you
reset your head away.  The above "reset --hard HEAD~4", before doing
what it was told to do, could perform:

	git rev-list HEAD~4..HEAD

(replace "HEAD~4" with whereever you are attempting to go) and see
if any of the listed commits is an ancestor of @{upstream} of the
current branch.  And if that is true, then your updated "reset" can
issue a warning, just like "git checkout branchname" to leave the
detached HEAD state gives you a friendly warning.

  reply	other threads:[~2012-10-05  3:12 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-03 14:49 git reset respect remote repo (make git idiot proof) Geoffrey De Smet
2012-10-03 14:59 ` Ramkumar Ramachandra
2012-10-03 15:12   ` Geoffrey De Smet
2012-10-03 16:40 ` Phil Hord
2012-10-04  8:59   ` Geoffrey De Smet
2012-10-05  3:11     ` Junio C Hamano [this message]
2012-10-05  5:35     ` Dirk Heinrichs
2012-10-03 16:52 ` Andreas Schwab
2012-10-04  8:56   ` Geoffrey De Smet

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7vsj9tvci0.fsf@alter.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=ge0ffrey.spam@gmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).