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

Re: Moving a directory with history from one repository to another while renaming

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Jun 21, 2007, 14:05 UTC
Message-ID
<Pine.LNX.4.64.0706211504060.4059@racer.site>
In-Reply-To
<200706211457.29030.andyparkins@gmail.com>
Hi,
On Thu, 21 Jun 2007, Andy Parkins wrote:
Show 14 quoted lines
> On Thursday 2007 June 21, Jeff King wrote:
> 
> > You can do this much more efficiently by just operating on the index.
> > Something like:
> >
> > git-filter-branch --index-filter \
> >  'git-ls-files -s | sed -n 's/change/paths/p' | git-update-index
> > --index-info' \ directorymoved
> 
> :-D  Even better.  I am definitely in the "fan of git-filter-branch" camp.
> 
> Thanks for sharing that line; I've actually found it instructive for more than 
> just git-filter-branch.  I definitely hadn't appreciated the fact that the 
> index can be so easily manipulated.

You have to adapt the line minimally: As is, it will possibly catch the wrong names, and it does not _move_ the directory, but rather _copy_ it.

So I think something like
git-ls-files -s | sed "s-\t-&newsubdir/-" |
  GIT_INDEX_FILE="$GIT_INDEX_FILE".new git-update-index --index-info &&
mv "$GIT_INDEX_FILE".new "$GIT_INDEX_FILE"
is needed.

Ciao, Dscho

Previous: Andy Parkins
Message 4 of 4 in “Moving a directory with history from one repository to another while renaming”
  1. Andy ParkinsJun 21, 2007
  2. Jeff KingJun 21, 2007
  3. Andy ParkinsJun 21, 2007
  4. Johannes SchindelinJun 21, 2007

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.