git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: git reset respect remote repo (make git idiot proof)

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 5, 2012, 03:11 UTC
Message-ID
<7vsj9tvci0.fsf@alter.siamese.dyndns.org>
In-Reply-To
<k4jj5n$72b$1@ger.gmane.org>
Geoffrey De Smet <ge0ffrey.spam@gmail.com> writes:
Show 17 quoted lines
> 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.

Previous: Geoffrey De SmetNext: Dirk Heinrichs
Message 6 of 9 in “git reset respect remote repo (make git idiot proof)”
  1. Geoffrey De SmetOct 3, 2012
  2. Ramkumar RamachandraOct 3, 2012
  3. Geoffrey De SmetOct 3, 2012
  4. Phil HordOct 3, 2012
  5. Geoffrey De SmetOct 4, 2012
  6. Junio C HamanoOct 5, 2012
  7. Dirk HeinrichsOct 5, 2012
  8. Andreas SchwabOct 3, 2012
  9. Geoffrey De SmetOct 4, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.