I want to sync my local repository so as to make the local an exact copy of the master. Since checking it out I have added several files to my local, not present in master, that I do not wish to commit. Nevertheless, in this procedure, I want to erase all differences of my local from master: when I am done, the additional files in local will have been deleted.
An earlier question offers a strategy to make local like master: Restablecer la rama del repositorio local para que sea como el repositorio remoto HEAD
But this does not work for me. The recommended commands, git fetch origin git reset --hard origin/master
do not erase the additional files from my local, even though git status indicates local and master are identical. And also, in one case the master's version of a file did not replace my local version.
¿Alguna idea sobre cómo hacer esto?
preguntado el 13 de septiembre de 13 a las 10:09
Actually, the commands you tried will reset all tracked files to the state of
origin/master. However, git doesn't touch untracked files (usually). In fact, the whole purpose of the "untracked file"-feature is, to be able to have file completely independent of git inside the repository.
However, you can still make git delete untracked files if you want to:
To delete all untracked files from your repository, type:
git clean -f
Be aware, as the files you delete are untracked, they will be lost forever.
I think that you're mixing two things up:
- updating your repository to be in sync with remote repository
- resetting your working directory to be identical to a particular commit.
Para actualizar tu repositorio (i.e. the database in which git stores all information about your project and its history), use
git fetch remote_repository_name (
remote_repository_name es generalmente
origin). After running this command, all commits and objects that are present in the remote repository
origin will be present in your repository.
Ahora, la directorio de trabajo - i.e. the files that you see in the folder containing the project - is something different from the repository database itself. Notice that you cannot make the working directory to be the same as the remote repository, because these are two different kinds of things (a directory with files vs. a git database). You can reset your working directory to reflect a particular commit (for example tip of
master derivarse de
origin) - here @oznerol256's answer te da lo que necesitas.
As the files are not yet committed, you can use:
rm -rf ./* git reset --hard HEAD
This will wipe out all files, then revert the directory back to its original state.