简体   繁体   English

git checkout [commit]和git checkout [commit]文件之间的区别

[英]Difference between git checkout [commit] and git checkout [commit] file

Here both are listed as changing the Working Directory(WD). 这两个都列为更改工作目录(WD)。

https://git-scm.com/book/en/v2/Git-Tools-Reset-Demystified https://git-scm.com/book/en/v2/Git-Tools-Reset-Demystified

However one is WD safe(git co commit) and another one unsafe. 但是一个是WD安全(git co commit),另一个是不安全。

Can you explain by giving an example? 你能举个例子来解释吗?

Git checkout will take your repo to state where is head . Git结帐将带您的仓库回覆到哪里。 Its is considered safe as you will not lose any work . 它被认为是安全的,因为您不会丢失任何工作。 You can come back to normal state by doing git checkout master or . 您可以通过执行git checkout master或来恢复正常状态。

But git checkout file , will erase all the changes you made on the file and take the file to last commit state . 但是git checkout文件,将删除您对该文件所做的所有更改,并使该文件进入最后的提交状态。 So you lose all you work and it is not recoverable . 因此,您将失去所有工作,并且无法恢复。 So it is considered unsafe . 因此,它被认为是不安全的。

You could use git stash command to keep all the changes , which will take your code HEAD state and it is recoverable . 您可以使用git stash命令保留所有更改,这将使您的代码HEAD状态且可恢复。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM