{"thread":{"id":"56282","subject":"'git log' doesn't keep log of un-removed and then renamed directory","startedAt":"2021-08-14T09:20:38Z","lastAt":"2021-08-14T10:22:57Z","messageCount":3,"participants":["Yuri","Chris Torek"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"432731","messageId":"75911f47-1433-f0a4-7d46-f1fb2fd44cf4@rawbw.com","threadId":"56282","inReplyTo":null,"subject":"'git log' doesn't keep log of un-removed and then renamed directory","fromName":"Yuri","fromEmail":"yuri@freebsd.org","sentAt":"2021-08-14T09:09:27Z","receivedAt":"2021-08-14T09:20:38Z","isPatch":false,"sender":{"key":"yuri@freebsd.org","avatar":null},"body":"In the FreeBSD ports tree I restored the previously removed directory \nmath/dynare:\n\n1. git checkout 3fb72e318f7be~1 -- math/dynare\n\n2. git mv math/dynare science/dynare\n\n3. rm -rf science/dynare && cp -r science/dynare.new science/dynare\n\n4. git add science/dynare\n\n5. git commit science/dynare\n\n\nAfter this 'git log science/dynare' only shows my last commit, and not \nthe previous history of 'math/dynare' that existed before its removal.\n\n\nThe above sequence of commands should have kept and migrated the history \nof math/dynare to science/dynare, but it didn't.\n\n\nThe corresponding subversion command sequence keeps history.\n\n\nYuri\n\n\n"},{"id":"432733","messageId":"CAPx1Gvdb=rtjWmc1Qe5iZyuwSF+s-YO7G__VUZ=iZw3x4bAKCw@mail.gmail.com","threadId":"56282","inReplyTo":"75911f47-1433-f0a4-7d46-f1fb2fd44cf4@rawbw.com","subject":"Re: 'git log' doesn't keep log of un-removed and then renamed directory","fromName":"Chris Torek","fromEmail":"chris.torek@gmail.com","sentAt":"2021-08-14T10:18:59Z","receivedAt":"2021-08-14T10:21:35Z","isPatch":false,"sender":{"key":"chris.torek@gmail.com","avatar":"https://avatars.githubusercontent.com/u/16826774?v=4"},"body":"On Sat, Aug 14, 2021 at 2:21 AM Yuri <yuri@freebsd.org> wrote:\n>\n> In the FreeBSD ports tree I restored the previously removed directory\n> math/dynare:\n>\n> 1. git checkout 3fb72e318f7be~1 -- math/dynare\n\n[remaining complex shuffling action that mimics what's needed\nin SVN, snipped]\n\nGit is not SVN; do not expect it to behave *like* SVN.\n\nIn particular, Git does not have file history.  Git has only commits.\n\nSVN has commits, but SVN commits contain file history.  In Git, the\ncommits *are* the history, and are the *only history*.  Each commit has\na full snapshot of every file, under the names you told Git to use, with\nthe contents that you told Git to save.\n\nThe command `git log science/dynare` tells Git: Look through\ncommits, one by one, and whenever there's a file whose name\nstarts with `science/dynare` that's different in *this* commit, vs the\nprevious one, tell me about this commit.  Since the old commits\nhave files named `math/dynare/something` instead, Git doesn't\ntell you about them.\n\nThe `git log` command has a flag, `--follow`, that has a trick up its\nsleeve (wait: does `git log` have sleeves? well, anyway). This trick\nis a bit limited though. Let's say there's a README file in the\nscience/dynare/ directory, as of the latest commit.  If you run:\n\n    git log --follow science/dynare/README\n\nGit will look at *this* commit and find the file, and will look at this\ncommit's *parent* and *not* find the file, because the parent does\nnot have `science/dynare/README` in it.  But the parent does\nhave `math/dynare/README` in it *and that file exactly matches*\nthis commit's copy.  So `git log` will tell you about this commit and\nsay that the file was *renamed*.  From this point backwards,\n`git log` will be looking, not for `science/dynare/README`, but\ninstead for `math/dynare/README`.\n\nUnfortunately, the `--follow` trick only works on *one file*. But it\nwill let you know that if you re-run your `git log` with `math/dynare`\nyou can see what happened before the renaming.\n\nA future `git log` really should be smarter about detecting the\nwhole-subtree renaming, and be able to follow it.  This won't\nrequire any change in the repository, just a smarter `git log`.\nBut someone has to write that smarter `git log`.\n\nChris\n"},{"id":"432734","messageId":"CAPx1Gve4GoMtH5s-3-RQgf0szvpW-DdFn7GygzAzg_e6vTCrLQ@mail.gmail.com","threadId":"56282","inReplyTo":"CAPx1Gvdb=rtjWmc1Qe5iZyuwSF+s-YO7G__VUZ=iZw3x4bAKCw@mail.gmail.com","subject":"Re: 'git log' doesn't keep log of un-removed and then renamed directory","fromName":"Chris Torek","fromEmail":"chris.torek@gmail.com","sentAt":"2021-08-14T10:22:21Z","receivedAt":"2021-08-14T10:22:57Z","isPatch":false,"sender":{"key":"chris.torek@gmail.com","avatar":"https://avatars.githubusercontent.com/u/16826774?v=4"},"body":"I should add: to make this work in that future smarter\n`git log` command, be sure to:\n\n 1. commit the un-removal first; then\n 2. commit the rename (you can just `git mv` the\ndirectory and commit)\n\nso that the future smarter `git log` has an easy way of\nfinding this.  Ideally, it would find this even without that,\nbut having all the files / sub-trees have identical hash IDs\nwill make this much faster and easier.\n"}]}