Re: Request: `git restore $commit $file` shouldn’t override uncommited changes
- From
Johannes Altmanninger <aclopte@gmail.com>
- Date
- Apr 27, 2021, 19:29 UTC
- Message-ID
- <20210427192906.7obdkopxwajqnv53@gmail.com>
- In-Reply-To
- <pYZzGPZTHnJjYBKrUAVGcso74I_xJgfzNpSwDN94fhYcDoOamp62-IFvxVrU056uw0txy3MTHYSwny_II0XY4trSY5_E25q7EXwhNHjy3VY=@pm.me>
> I would have expected that `git restore $commit $file` would copy the > content of said file from another revision only if your don’t have > uncommitted changes or to get an error.
The positional arguments to "git restore" are files. So that command will error unless a file called $commit exists. (You shell's tab completion should guide you here.) You can use the --source option to specify the commit.
> If it was really what I wanted to do, I would have expected to either do > `git restore $file && git restore $commit $file`, directly `git restore > --force $commit $file` or something similar.
Is your question that you expect a command like
git restore --source=some-commit some-file
to error if you have uncommitted changes (to "some-file")? And instead you would run
git restore some-file git restore --source=some-commit some-file