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

[PATCH 0/6] Reusing "checkout [-m]" logic for "reset --merge"

From
Junio C Hamano <gitster@pobox.com>
Date
Dec 6, 2008, 01:54 UTC
Message-ID
<1228528455-3089-1-git-send-email-gitster@pobox.com>

"checkout" that switches the branches, and "reset" that updates the HEAD, have some similarities. Their major difference is that "checkout" affects which branch HEAD symref points at, while "reset" affects what commit such a branch pointed at by the HEAD symref points at. Interestingly, when your HEAD is detached, they operate on the same thing.

They both change the commit pointed at by your HEAD from one commit to another. And what "checkout" and "reset --merge" do to the index and the work tree while doing so are exactly the same. Keep your local changes, while updating everything else from what is in the current commit to the one we are switching to.

There is one difference, though.

"reset --merge" does not have an equivalent of "checkout -m" that falls back to three-way merge to resolve the conflicts at the content level. This series, which is still a WIP, is an attempt to do so.

There are few things to notice that this series doesn't do:
 - What "reset --hard" and "checkout -f HEAD" do to the index and work
   tree (at least in naive thinking) ought to be the same.  This series
   does not attempt to unify these.
 - "reset --merge" is left as posted by Linus, and it does only "git
   checkout" equivalent, without "-m" (yet).

The latter can be enabled by changing a single line (see comment in reset_index_file() in [Patch 6/6]), but I haven't done so yet.

While investigating for the former possibility, I noticed one interesting thing what "checkout -f" does *NOT* do. Starting with an index with conflicts, "git checkout -f HEAD" keeps higher stage entries.

For example, you can insert "exit" before the "D/F resolve" test in t1004, run the test (this leaves a handful higher stages in the index), go to the trash directory and say "git checkout -f HEAD".

It leaves a single stage #1 entry (subdir/file2). It probably is a bug in unpack-trees, but I didn't take a very deep look at it.

Junio C Hamano (6):
  builtin-checkout.c: check error return from read_cache()
  read-cache.c: typofix in comment
  Make reset_tree() in builtin-checkout.c a bit more library-ish
  builtin-checkout.c: refactor merge_working_tree()
  builtin-commit.c: further refactor branch switching
  builtin-reset.c: use reset_index_and_worktree()
 builtin-checkout.c |  193 +++++++++++++++++++++++++++++-----------------------
 builtin-reset.c    |   66 +++++++++++++++++-
 read-cache.c       |    2 +-
 reset.h            |   11 +++
 4 files changed, 183 insertions(+), 89 deletions(-)
 create mode 100644 reset.h
Next: Junio C Hamano
Message 1 of 8 in “Reusing "checkout [-m]" logic for "reset --merge"”
  1. 0/6 Reusing "checkout [-m]" logic for "reset --merge"Junio C Hamano, Dec 6, 2008
  2. 1/6 builtin-checkout.c: check error return from read_cache()Junio C Hamano, Dec 6, 2008
  3. 2/6 read-cache.c: typofix in commentJunio C Hamano, Dec 6, 2008
  4. 3/6 Make reset_tree() in builtin-checkout.c a bit more library-ishJunio C Hamano, Dec 6, 2008
  5. 4/6 builtin-checkout.c: refactor merge_working_tree()Junio C Hamano, Dec 6, 2008
  6. 5/6 builtin-commit.c: further refactor branch switchingJunio C Hamano, Dec 6, 2008
  7. 6/6 builtin-reset.c: use reset_index_and_worktree()Junio C Hamano, Dec 6, 2008
  8. Linus TorvaldsDec 6, 2008

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.