Asked  7 Months ago    Answers:  5   Viewed   46 times

I would like to rename/move a project subtree in Git moving it from

/project/xyz

to

/components/xyz

If I use a plain git mv project components, then all the commit history for the xyz project gets lost. Is there a way to move this such that the history is maintained?

 Answers

44

Git detects renames rather than persisting the operation with the commit, so whether you use git mv or mv doesn't matter.

The log command takes a --follow argument that continues history before a rename operation, i.e., it searches for similar content using the heuristics:

http://git-scm.com/docs/git-log

To lookup the full history, use the following command:

git log --follow ./path/to/file
Tuesday, June 1, 2021
 
Andres
answered 7 Months ago
54

Looks like the following process had a lock on the .gitindex file:

ssh-agent.exe
C:UsersTomAppDataLocalGitHubPortableGit_8810fd5c2c79c73adcc73fd0825f3b32fdb816e7binssh-agent.exe

I killed the process and ran git reset HEAD and looks like I'm back to normal now.

Thursday, June 17, 2021
 
tompave
answered 6 Months ago
89

This is not possible. If you have committed a file, then it will be pushed. The push action only acts on commits, not on a file basis.

But you could use a submodule for your sensitive data and keep this submodule on your local machine, while you push the regular git repository to the remote machine.

Sunday, August 1, 2021
 
Denis
answered 4 Months ago
86

As illustrated in this thread

Git doesn't care about individual files or renames, it tracks whole trees.
What it shows as a rename is just its best guess based on the contents of the two files.

Git status does perform rename detection using a heuristic.
But once you commit, you will see the two files are kept separate.

Thursday, August 5, 2021
 
RustyFluff
answered 4 Months ago
15

GitHub uses the Linguist library for source code detection; Linguist treats all of the paths defined in its' vendor.yml as vendored and won't include them in the language statistics for a repository.

You can specify something different for your repo by editing your repo's .gitattributes file. To treat a path as a vendored file, add the path followed by linguist-vendored:

special-vendored-path/* linguist-vendored

To treat an otherwise vendored path as unvendored, use linguist-vendored=false:

jquery.js linguist-vendored=false

Source

Wednesday, August 11, 2021
 
ala
answered 4 Months ago
ala
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :
 
Share