Matt Molnar
Matt Molnar

Reputation: 2542

Can I make atomic checkouts with Git?

In switching between branches in Git, there's been times where an application was preventing local file changes. I then close the application and run git checkout [branch] again. However the second time, I will be informed that the checkout cannot be performed because I would lose local changes (even though I didn't make any). This appears to be due to the previous checkout being performed partially by git, thus a lot of the changes are actually git trying to checkout the specified branch. When run the 2nd time, Git doesn't realize that the branch never changed and thinks I have local changes.

Is there any way to force Git to make a checkout attempt atomic? That is, if it fails, undo the whole process in the working directory?

Upvotes: 0

Views: 163

Answers (1)

Jasen
Jasen

Reputation: 12392

if you can, switch to a system that doesn't allow ordinary applications to do mandatory file locking.

If not git checkout . will overwrite any files it thinks have been modified

Upvotes: 1

Related Questions