3

IN order to revert a item from staging area we use git reset filename or git reset .

however git also gives me a prompt (mentioned below) after I do git status.

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)

This is also unstages file from staging area.

Also in order to revert changes there is known command

git checkout filename

However same can be achieved using git restore filename

What are the fundamental differences between them? and why git is pushing forward to use git restore

Jatin Mehrotra
  • 9,286
  • 4
  • 28
  • 67
  • 4
    Does this answer your question? [What is the \`git restore\` command and what is the difference between \`git restore\` and \`git reset\`?](https://stackoverflow.com/questions/58003030/what-is-the-git-restore-command-and-what-is-the-difference-between-git-restor) – Dev-vruper Feb 21 '21 at 14:48
  • I have added more explanation, and that answer doesn't answer as to why github is pushing or encouraging to use `git restore` – Jatin Mehrotra Feb 21 '21 at 15:06
  • 1
    Nothing in this question relates to GitHub. If your question is actually about GitHub, perhaps include some quote and link to GitHub where they discuss the issue you're challenging. Currently this question shows the messages produced by Git, which are answered in the question linked to. – grg Feb 21 '21 at 18:12
  • Note that `git restore` is, in a significant way, "half of `git checkout`". The other half is in `git switch`: the two new commands were introduced in Git 2.23 as an experiment in splitting the overly complicated `git checkout` command into two simpler / easier-to-use commands. VonC's answer in the linked question gives more of the history (including an important bug fix in `git restore`). – torek Feb 21 '21 at 22:29

1 Answers1

6

Reverting the working tree version of a file to match the index version is one of many things git checkout can do (depending on what args you give it).

Reverting the index version of a file to match the version in the HEAD commit is one of many things git reset can do (depending on what args you give it). It is different from the above usage of checkout in that one changes the index and the other changes the worktree. (There are other checkout operations that also affect the index; and that's part of the issue that leads to the next point...)

git restore is a relatively new command that groups these functions together, while "un-grouping" them from the unrelated things those other commands do. The docs push toward using it because it's the newer, more clear way to perform the operations it covers. The operation is equivalent; it's just new porcelain to make git more usable.

I don't know what github has to do with using one command or the other. If there's some way in which you think they're pushing restore over the others, they'd be right anyway for the reason noted above - that it's the modern way to perform those operations.

Mark Adelsberger
  • 42,148
  • 4
  • 35
  • 52