On 5 Sep 2013 08:16, "Thomas Ferris Nicolaisen" <tfn...@gmail.com> wrote: > > > > On Thursday, September 5, 2013 7:31:04 AM UTC+2, Jean-Michel FAYARD wrote: >> >> I want to be able to rename as freely as possible the filenames that are on my github repository >> The thing is that I don't want to have ugly broken links on my future website. >> There should be a javascript redirection from each link that used to work fine to the actual version of it >> >> I think it will be quite easy to hack jekyll in order to have those necessarry redirections >> >> But for this, I need to have a `REDIRECTIONS` textfile that will be automatically updated each time a commit changes to my git repository >> I have learned that pre- and post-commit hooks exist but I don't know yet how they work > > > You can read more about them in the docs, but I don't think you'll find what you're looking for in the post-commit hook, because you can't change a commit during a hook. > > One strategy a lot of people apply in this situation is to use the git pre-commit hook as an early warning system for something you forgot to do. In your situation you could write a hook that inspects the incoming commit, parses together a list of renamed files, and then checks if they are listed in REDIRECTIONS. If not, print an error and return non-zero. This will prevent you from committing if you have forgotten to update REDIRECTIONS. > > Now, maybe you could make a little helper script that uses Git to make changes to REDIRECTIONS for you, but I doubt it's that much work to do manually anyway. >> >> More importantly, I need your help to know how I can parse a git commit in order to have a list of newly "renamed" files >> I say "renamed" files because I have leraned that for git, there is not really such thing as a rename operation >> At first it confused me, but then I understood that Linus, who is much smarter than me ;-), had good reasons to do that > > > Even though renames aren't explicitly stored in Git, they can be detected, and git log will detect renames by default. You can further tweak rename detection, as it is a bit of a science if you want to get more into it, have a look at the git log docs if you want to do so. > >> But still, for my static website generator, I do need to know which files were renamed since the last commit (a broken url is a broken url) >> that is, which files git detected as similar enough so that we can safely assume it was a rename operation > > > To see local changes in Git, you use `git status`. In contrast from git log, status will not detect renames immediately. You have to stage the changes with `git add -A` (short explanation: before staging, the changes are not in Git's database, and before that Git can't do anything intelligent with rename detection).
Well, there is a magic command for that: git mv. It renames the file AND stages the modification immediately. Also some tools (Netbeans, to name one) do exactly the same if you rename a file tnrough its GUI. > > Example: > > ➜ ~/prefs/[master]>mv README.md foo.md > ➜ ~/prefs/[master]✗>git status -s > D README.md > ?? foo.md > ➜ ~/prefs/[master]✗>git add -A > ➜ ~/prefs/[master]✗>git status -s > R README.md -> foo.md > > -- > You received this message because you are subscribed to the Google Groups "Git for human beings" group. > To unsubscribe from this group and stop receiving emails from it, send an email to git-users+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/groups/opt_out. -- You received this message because you are subscribed to the Google Groups "Git for human beings" group. To unsubscribe from this group and stop receiving emails from it, send an email to git-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.