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

Re: git-reset HEAD --permissions-only

From
Jeff King <peff@peff.net>
Date
Mar 15, 2011, 01:32 UTC
Message-ID
<20110315013223.GB31865@sigill.intra.peff.net>
In-Reply-To
<illts0$c6q$1@dough.gmane.org>
On Mon, Mar 14, 2011 at 03:29:51PM -0500, Neal Kreitzinger wrote:
> Is there a way to only reset the file permissions of the working-tree
> to match HEAD file permissions without resetting the content of the
> files?

Not directly, but you could munge a patch to do so and apply it in reverse. For example:

  git diff "$@" |
  perl -ne '
    if (/^diff/) { $diff = $_ }
    elsif (/^old mode/) { print $diff, $_ }
    elsif (/^new mode/) { print $_ }
  ' |
  git apply -R

Which seems a little more complicated than it needs to be, but we don't (AFAIK) have a way to say "show me only the mode changes from this diff in an applicable form". The closest would be "git diff --summary", but you cannot directly apply it (and I would hesitate to recommend parsing it).

You could also use "git checkout -p", which is designed for exactly this sort of picking-apart of a patch, but it has no way to specify "say yes to all of the mode changes, no to everything else"; you have to manually approve each hunk. Which doesn't work if you have a lot of these files.

I guess for mode changes, you don't care if you chmod something that is already fine. So yet another way to do it would be:

  git ls-files -sz |
  perl -0ne '
    /100(\d+).*?\t(.*)/ or next;
    -e $2 or next;
    chmod(oct($1), $2)
      or die "chmod failed: $!";
  '

Hope that helps, -Peff

Previous: Neal KreitzingerNext: Neal Kreitzinger
Message 2 of 4 in “git-reset HEAD --permissions-only”
  1. Neal KreitzingerMar 14, 2011
  2. Jeff KingMar 15, 2011
  3. Neal KreitzingerMar 16, 2011
  4. Jeff KingMar 17, 2011

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.