What is the practical difference between `git rm --cached`,` git reset - `and` git reset HEAD` so as not to affect the changes?

I have an alias unstageto remove changes from the staging area.

unstage = reset --

I noticed that git help offers git reset HEAD. I also noticed that I git rm --cachedwould do the same.

Except that git rm --cachedit will not clear the entire step without -r, is there a practical difference between these methods for removing changes from the staging area? Practically, I mean, can you show a scenario where they will give different results? Or can I safely use them interchangeably?

+4
source share
3 answers

git reset , :

: git HEAD

git reset == git reset HEAD

- .

, :

git reset --mixed AND git rm --cached

(reset - )

git reset --mixed
           Resets the index but not the working tree (i.e., the changed files are preserved but not marked for
           commit) and reports what has not been updated. This is the default action.

git rm --cached
       Use this option to unstage and remove paths only from the index. Working tree files, whether modified or
       not, will be left alone.enter code here

, , git rm --cached , . Git reset - , , "", .

+4

( , ) :

  • git reset [<tree-ish>] path [path...] <tree-ish> ( HEAD, ) , , <tree-ish>,

    • , blob a398bc837d, blob.
    • , .
  • git rm --cached path [path ...], , path .

, :

  • HEAD foo.txt.
  • git add foo.txt .
    • git reset [HEAD] foo.txt foo.txt, , , HEAD.
    • git rm --cached foo.txt foo.txt .

, , , foo.txt - , .

, git reset HEADgit add.

:

  • git add pathname , pathname . pathname , . ?
  • git add, git reset HEAD , git add: git add - , . , .

    , git rm --cached . , "" git add , git add , git rm --cached.

+1

, git rm --staged <file> git reset HEAD <file>

, .

git rm --staged , , . git add .

git reset , , . git add .

, .

git rm --staged some-file . . git rm --staged. git add . , , , . . , .

From the git reset HEAD some-filechanges made to the file since the last commit will be deleted from the staging area, but the file is still being tracked. Therefore, when you return to commit where you started git reset HEAD some-file.txt, the file will still be there, but there will be no changes.

To disorder the file should be used git reset HEAD <file>.

0
source

Source: https://habr.com/ru/post/1610661/


All Articles