Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Move a file to a new folder, keeping Git history

I am looking to move a folder so that it resides in another folder.

Currently: /folder1, moved to /holder/folder1, for example.

What is the easiest way to do this both on my home machine (Mac) and git to ensure that all of the history of the files within that folder remain on github.

Sorry for the newb question. I have only a very basic working knowledge of git, and would like to keep this as simple as possible.

Thanks!

like image 377
Stephen G Avatar asked Jan 12 '11 06:01

Stephen G


People also ask

How do I move files and keep my git history?

Merge the files into the new repository B. Step 2: Go to that directory. Step 3: Create a remote connection to repository A as a branch in repository B. Step 4: Pull files and history from this branch (containing only the directory you want to move) into repository B.

Does git mv retain history?

Git move or mv helps us to rename or move files within a git repository without deleting its history.

Does git track moving files?

Git keeps track of changes to files in the working directory of a repository by their name. When you move or rename a file, Git doesn't see that a file was moved; it sees that there's a file with a new filename, and the file with the old filename was deleted (even if the contents remain the same).

How do I move a file from one directory to another in git?

Use git status to check the changes staged for commit. Commit the file that you've staged in your local repository. $ git commit -m "Move file to new directory" # Commits the tracked changes and prepares them to be pushed to a remote repository.


1 Answers

From git documentation,

git mv [-f] [-n] <source> <destination>
git mv [-f] [-n] [-k] <source> ... <destination directory> 

In the first form, it renames , which must exist and be either a file, symlink or directory, to . In the second form, the last argument has to be an existing directory; the given sources will be moved into this directory.

The index is updated after successful completion, but the change must still be committed.

like image 130
Raghuram Avatar answered Sep 20 '22 10:09

Raghuram