Git - Delete files with rm (not with "git rm") and reflect it in the index, the local repository and the remote repository

4

A few days ago I started studying Git. I understood everything quite well, although I have some doubts about how to delete files.

Precisely, what I want to know is how I delete a file / directory with the command " rm " of linux and that this action is not only reflected in the index ( stage ), but also in the local repository and in the remote repository.

I understand that if I delete a file / directory and follow it with the command "git add", this change will be reflected in the index ( stage ), but not in the local repository ( git commit ) or in the remote repository ( git push ). However, when I delete a file with the " rm " command in linux and add it to the index (stage) and then execute the " git commit " and " git push " commands, the deleted files also disappear from the local repository and the remote repository.

Is it necessary to use the " rm " command from Git or can I use the " rm " command of linux (more comfortable for me) and reflect in some way such an action, not only in the index ( stage ), but also in the local repository and in the remote repository?

Thank you.

    
asked by José Galeota 07.08.2017 в 15:41
source

2 answers

5

If you use only rm you have to do a git add <ficha_a_eliminar> , with git rm <ficha_a_eliminar> you do it all in one step.

  

Another thing you might want to do is keep the file in your   working directory, but remove it from your preparation area.   In other words, you may want to keep the file on your disk   hard, but interrupt his monitoring by Git. This results   particularly useful when you forgot to add something to your file    .gitignore and you added it accidentally, as a log file   huge, or a lot of files.

     

To do this, use the option    --cached :

git rm --cached <ficha_a_eliminar>

+ Info

    
answered by 07.08.2017 / 16:14
source
1

Changes are first made in your local repository, when you make push make changes in the remote repository.

to locally add a / s file to git is:

git add 'archivoSeleccionado'

you finish adding locally you must do 'commit'

git commit -m 'nuevo commit'
  

to make changes to the remote repository you must do push

git push origin 'nombreDeTuRama'

to locally delete a / s file in git is:

git rm 'archivoSeleccionado'

or if you want to delete folders you use rm -r

git rm -r 'carpetaSeleccionado'

you finish adding locally you must do 'commit'

git commit -m 'nuevo commit'
  

to make changes to the remote repository to push

git push origin 'nombreDeTuRama'
    
answered by 07.08.2017 в 15:53