Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing subfolder name in git project without losing file history?

Tags:

git

git-gui

FYI, I'm pretty new to git, using mostly gitgui.

When I change the name of an already tracked folder containing already tracked files in my project, git sees all the files in the folder as new untracked files. How do I make git understand that I only changed the name of the folder, so that I don't "lose" the history of the files contained in that folder?

like image 314
AMO Avatar asked Feb 27 '23 18:02

AMO


2 Answers

Git doesn't care about your files or folders. There I said it. It tracks your content. After you move your files it'll show in git status as deleting a set of files/folders and a creation of files/folders. After your commit Git will detect that it's already seen this exact content and be able to follow not only the "files" and "folders" but even if you moved code from one file to another by the way it manages chunks.

Welcome to Git!

like image 114
Marco Ceppi Avatar answered Mar 01 '23 07:03

Marco Ceppi


Git doesn't explicitly track moves/renames or copies. Instead, it detects them when it's asked to. Do the move, and run git diff -M.

like image 35
Phil Miller Avatar answered Mar 01 '23 07:03

Phil Miller