git SourceTree 中停止跟踪和丢弃文件有什么区别

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30857183/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 03:17:50  来源:igfitidea点击:

What is the difference between Stop Tracking and Discard File in git SourceTree

gitatlassian-sourcetree

提问by MistyD

I wanted to know what the difference is between discarding a file and and stop tracking a file in git using source-tree. If I deleted a file in my updated code and I want that file deleted on the repository too should I mark it as stop tracking or should I discard it during the commit process

我想知道在 git 中使用 source-tree 丢弃文件和停止跟踪文件之间有什么区别。如果我在更新的代码中删除了一个文件,并且我也希望在存储库中删除该文件,我应该将其标记为停止跟踪还是应该在提交过程中丢弃它

回答by Ken Lyon

The one detail not covered by the first answer is that Stop Trackingdoes not delete the local file. It only removes it from source control.

第一个答案未涵盖的一个细节是停止跟踪不会删除本地文件。它只会将其从源代码管理中删除。

  1. If you want to keep the file locally (maybe it's a .suo file storing Visual Studio settings that you decide shouldn't have been in source control) but remove it from the repository, you should use Stop Tracking. After this, if you see the file listed in Unstaged files, you can use right-click > Ignore...in SourceTree to update your .gitignore file to ignore the file in future.
  2. If you want to delete your file both locally and in the repository, you should use Remove. (to use the SourceTree term)
  3. Finally, if you only want to revert your local changes without
    changing the repository at all, use Discard.
  1. 如果您想将文件保留在本地(可能它是一个存储 Visual Studio 设置的 .suo 文件,您认为不应在源代码管理中)但将其从存储库中删除,则应使用Stop Tracking。在此之后,如果您看到Unstaged files 中列出的文件,您可以在SourceTree中使用右键单击 > Ignore...更新您的 .gitignore 文件以在将来忽略该文件。
  2. 如果您想在本地和存储库中删除您的文件,您应该使用Remove。(使用 SourceTree 术语)
  3. 最后,如果您只想恢复本地更改而不
    更改存储库,请使用Discard

回答by David Deutsch

In SourceTree, selecting "discard" on a file just throws away your local changes; stop tracking removes it from the repository. However, as long as you have deleted the file on your local drive, and you can see that deletion in the "Staged Files" section of SourceTree, it will be deleted in the repository as well when you commit.

在 SourceTree 中,在文件上选择“丢弃”只会丢弃您的本地更改;停止跟踪会将其从存储库中删除。但是,只要您删除了本地驱动器上的文件,并且您可以在 SourceTree 的“暂存文件”部分中看到该删除,那么当您提交时,它也会在存储库中删除。