-1

I recently found out I could override a file from my tracking remote branch doing the next : "git checkout origin/remoteBranchName nameFile.txt". But I have some questions:

  1. Having changes in this file not commited, executing the command does not warn about losing changes and when switching to other branch it does. Why?

  2. I tried to override using hard reset but I think you cannot do it with one file. Why?

Thanks

Zoe
  • 27,060
  • 21
  • 118
  • 148
fernando1979
  • 1,727
  • 2
  • 20
  • 26

1 Answers1

1

I tried to override using hard reset but I think you cannot do it with one file. Why?

 $ git reset -- file.c 

According to https://git-scm.com/docs/git-reset

Reset a single file in the index

Suppose you have added a file to your index, but later decide you do not want to add it to your commit. You can remove the file from the index while keeping your changes with git reset.

$ git reset -- frotz.c (1)

$ git commit -m "Commit files in index" (2)

$ git add frotz.c (3)

  1. This removes the file from the index while keeping it in the working directory.

  2. This commits all other changes in the index.

  3. Adds the file to the index again.

Community
  • 1
  • 1
Punit Vara
  • 3,744
  • 1
  • 16
  • 30