简体   繁体   English

在提交到分支之前取回更改的文件

[英]Getting changed files back before commiting to branch

In VS I was working on a branch and I committed my changes before switching to another branch just in case to be safe.VS中,我在一个分支上工作,为了安全起见,我在切换到另一个分支之前提交了我的更改。 Now I went back to first branch but in " Changes " section of Team Explorer those committed changes do not show anymore.现在我回到第一个分支,但在Team Explorer的“ Changes ”部分,那些已提交的更改不再显示。 I do want them to still show because I need to do some code clean-up and review them.我确实希望它们仍然显示,因为我需要做一些代码清理并检查它们。 I also have some new changes too, all the same branch, just not commited those yet.我也有一些新的变化,都是同一个分支,只是还没有提交。 So how can I get everything to show in "Changes" section of Team Explorer ?那么我怎样才能让所有的东西都显示在Team Explorer的“更改”部分呢?

When you commit in Git, you are updating that branch of the project using your changes.当您在 Git 中提交时,您正在使用您的更改更新项目的该分支。 Thus, the files you committed are no longer in "Changes", and shouldn't be, because "Changes" is meant to show you what is different since the last commit.因此,您提交的文件不再在“更改”中,也不应该在“更改”中,因为“更改”旨在向您展示自上次提交以来的不同之处。

It seems you want to be able to see what files have been changed when switching branches.看起来你希望能够在切换分支时看到哪些文件被更改了。 You have a few options:你有几个选择:

  1. Stash your changes instead of committing them.存储您的更改而不是提交它们。 This can be done in VS by clicking the three dots and then choosing Stash .这可以在 VS 中通过单击三个点然后选择Stash来完成。 You can reload these changes when you return to the branch.当您返回分支机构时,您可以重新加载这些更改。 This might be better practice for you if you don't want to commit an incomplete file.如果您不想提交不完整的文件,这对您来说可能是更好的做法。

  2. Download a plugin like Git History to see your previous commits in VS.下载像Git History这样的插件来查看你之前在 VS 中的提交。 This is better practice if you want to commit something and then see what was changed in the future entirely in VS.如果您想提交某些内容然后完全在 VS 中查看将来发生的更改,这是更好的做法。

  3. Download GitHub Desktop.下载GitHub桌面。 This automatically does both of the former options for you.这会自动为您执行前两个选项。 If you don't care about having another application open while working, this might be best for you.如果您不关心在工作时打开另一个应用程序,这可能最适合您。

In a directory under git, it is not possible to make changes and ignore them. git下的一个目录,不能修改,忽略。 Unless you put the contents of the folder elsewhere so I advise you to be careful in writing commands除非你把文件夹的内容放在别处所以我建议你在写命令时要小心

Use the reset command to move back one commit.使用重置命令移回一个提交。

In a terminal, you can run:在终端中,您可以运行:

git reset --soft HEAD^    # the changes will stay in the index
                          # as if they were staged
# or
git reset HEAD^     # the changes will be on disk
                    # as if you had edited your files and not yet added them

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

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