Git, how do I move a file or folder to another repository keeping the history?

Asked

Viewed 2,666 times

1

I have 2 repositories:

/var/www/project

/var/www/project_disabled

I have a file in a specific folder within my repository project and I want to move this file with all its git history from the repository project to the repository project_disabled, How could I do that ? There’s a way ?

This would help me maintain the earlier versions of an older project that is more than 10 years old. and in case of error I could return with the file to the repository Official dinovo with all its history.

  • 2

    Why don’t you just delete that file? It will always be there in the repository if you want to go back and check its contents.

  • 1

    Interesting, but then we’ll have to start working another way, and it’ll be hard for people to agree to do it that way.

  • 2

    Okay, but people are using Git wrong. The idea of versioning is not to have "folders". If the code is no longer useful for the project, the ideal is to remove it anyway, and the version control is there for, in case in the future you realize that it is useful, the information has not gone away forever. It is similar to using version control and still leave "commented" code snippets in case they become useful again. Goes against the idea of the tool.

  • 1

    I found a solution, but I fully agree with you the version control this one for this, the problem is that I’m practically a beginner in the company and at first when they came up with it I had no knowledge and no arguments for it. I’m going to apply the solution I found here and I’m going to alert the staff about what you said, Thank you!

2 answers

3

You can simply clone your remote repository into another directory on your machine:

mkdir <repositorio-backup> -- cria o diretorio para o backup
cd <repositorio-backup>
git clone "https://github.com/path"

Another solution would be to create a backup branch, for example:

git checkout -b "branch-backup-master-2018/01/31"
  • Yes but the problem is that the project is huge and we are always updating changing, that is, we are always taking old classes and files and moving to the garbage repository or the repository of disabled files.

  • 1

    What about the suggestion to use a branch only for the purpose of storing the disabled files? It would solve your problem?

  • Solve, the problem is that we do not work this way, it has been years that we work with separate repositories and only now we realize that the history did not go there, because before we just took and played there.

1


I found a solution that is on this link here:

How to Move Changes Between Repositories Git Cherry-Pick

As I said to the friend above I know we are working the wrong way, but when this was proposed I had just joined as an intern and I didn’t have enough knowledge to question or argue, but finally I will talk to the staff and apply the solution I found.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.