On Fri, 12 Aug 2016 17:42:20 +0200
Pablo Rodríguez <oi...@web.de> wrote:

> I’m writing a book with git as control version system.
> I have been writing over 300 pages in a file named `my-book.tex`. Now
> I realize that I should start it from scratch. So I just `git mv
> my-book.tex old-draft.tex`.
> The new book will have also a `my-book.tex` file. The file has been
> added to git (at I commited some changes) with the name
> `new-book.tex`.
> Would it be problematic in the future if I `git mv new-book.tex
> my-book.tex`?
> I assume that git history will include the name change and it won’t
> change file contents. Is that right or am I missing something?

No, the history won't specifically include any information about the
name change (Git does not explicitly track renames of the entities it
manages) but nothing bad will happen notwithstanding.
What `git mv` did is removed -- from the commit you have recorded after
running that command -- the file as it was known under its old name and
added the same contents under its new name.  So, all the old history is
still there (in the commits before the rename) and all the new history
is there as well.

The only problem this might cause is that if you will run an unadorned

  git log old-draft.tex

command, it will stop traversing the chain of commits touching
"old-draft.tex" as soon as it hits the commit in which that file was
renamed.  If you want to make `git log` still dig deeper down the
history, you need to explicitly tell it to detect renames.
Please read the `git log` manual for the --find-renames (and
--find-copies) command-line options.

In other words, Git tracks contents paying little attention to where
exactly it is located in terms of files; and if you get concerned about
locations, Git is able to detect renames and copies at the time it
traverses the recorded history of your repository.

I understand that many people have difficulty grasping this approach
but note that quite many "questions" you may ask your history are
really not concerned with files.  Say, you can ask Git to look for the
commit in which a particular word or sentence was added or removed, and
it will search through the contents, not files.
That is, Git assumes a project is a whole thing.  If you are tempted to
consider histories of individual files in the project this might be
indicative of the fact you might better have different projects for
these different files.

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/d/optout.

Reply via email to