Start with the same folders and different files

1

I have a project that I just keep copying files to the server via SSH. Some of these files have been manually edited directly on the production server. Now I'm starting the Git versioning on Bitbucket, and I've already done an initial push of the files that are on my development machine.

How do you now merge what is on the production server and what is already in Git, knowing that the production server has some files modified directly there, and that does not contain these changes in the Git repository and neither on my machine of development?

I remember that I have not yet done any actions regarding Git on the production server. I am in doubt as to how to proceed from now on.

    
asked by anonymous 17.05.2016 / 16:47

1 answer

0

Do the following.

Suppose your project, on the server, is in the /var/www/projeto folder. Clone your repository to another folder, for example, /var/www/projeto_git :

git clone <repositório> <pasta de destino>

The branch that will be cloned will default to master . Create another branch named, for example, servidor :

git checkout -b servidor

Then, copy all files from the folder of your project to your repository:

cp -R /var/www/projeto /var/www/projeto_git

This is done by committing the files with a very clear message (for example, "server files") and sending them to the remote server:

git add --all
git commit -m <mensagem de commit>
git push -u origin servidor

In this way you will have two branches in your repository: master , which contains the original project, and servidor , which has your project modified with the files on the server where is hosted.

(Just a little detail: since you have little Git experience, be careful about versioning files with sensitive information in a public repository, prefer private repositories.)

Finally, if you want to download the modified project in your development environment, run the following command:

git checkout -b servidor origin/servidor

In this way, you can compare the two branches (that is, which files exist in one branch and not the other) and the differences between files with the command:

git diff master..servidor
    
17.05.2016 / 20:11