Re: Suggestion: make git checkout safer
- From
Jeff King <peff@peff.net>
- Date
- Jun 3, 2015, 09:06 UTC
- Message-ID
- <20150603090654.GD32000@peff.net>
- In-Reply-To
- <loom.20150603T104534-909@post.gmane.org>
On Wed, Jun 03, 2015 at 08:50:44AM +0000, Ed Avis wrote:
Show 23 quoted lines
> Currently a plain 'git checkout .' will revert any local changes, e.g. > > % mkdir test > % cd test > % git init > Initialized empty Git repository in /home/eda/test/.git/ > % echo hello >foo > % git add foo > % git commit -m. > [master (root-commit) 34f6694] . > 1 file changed, 1 insertion(+) > create mode 100644 foo > % echo goodbye >foo > % git checkout . > % cat foo > hello > > I suggest this is dangerous and by default 'git checkout' should only alter > files which do not have local changes (as would be reported by 'git diff'). > Only if --force is given should working tree differences be thrown away. > > % git --version > git version 2.4.0
That's what "git checkout <path>" is designed for. I'm not clear on what you expect "git checkout ." to do in this example, if not overwrite "foo". Can you elaborate?
-Peff