在 Git 中签入单个文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7079975/
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
Check in single file in Git?
提问by plenderj
My apologies if this is a silly question but I'm a VSS/VSTS guy trying to convert to Git :)
如果这是一个愚蠢的问题,我很抱歉,但我是一个试图转换为 Git 的 VSS/VSTS 人:)
I cloned a repository and pulled down a load of Visual Studio projects. While working on those projects I noticed that another developer had submitted an invalid .sql file. I fixed that .sql file for them, but am now unsure how to check in just that .sql file
我克隆了一个存储库并下载了大量 Visual Studio 项目。在处理这些项目时,我注意到另一位开发人员提交了一个无效的 .sql 文件。我为他们修复了那个 .sql 文件,但现在我不确定如何只签入那个 .sql 文件
My code changes are all half-baked so they can't be checked in at present. I have Git Extensions on my computer, and when I right click on the file in Windows Explorer and go Git Extensions -> Commit, there are lots of files referenced on the left. The file I want to check in has a symbol of a pencil, and the mass of other files all have a green + symbol.
我的代码更改都是半生不熟的,因此目前无法签入。我的计算机上有 Git 扩展,当我在 Windows 资源管理器中右键单击该文件并转到 Git 扩展 -> 提交时,左侧引用了很多文件。我要签入的文件有一个铅笔符号,其他文件的质量都有一个绿色+符号。
回答by knittl
you only need to add the changes in the sql file to the index and run git commit.
你只需要将 sql 文件中的更改添加到索引中并运行 git commit。
git add path/to/file.sql
git commit -m 'fixed broken sql file'
don't worry about your other changes, as long as you haven't add
ed them, they won't be committed (to make sure there are no changes in the index, run git reset
before adding the other change)
不要担心您的其他更改,只要您还没有add
编辑它们,它们就不会被提交(确保索引中没有更改,git reset
在添加其他更改之前运行)
回答by Paul R
It's probably safest/easiest to do it from the command line:
从命令行执行它可能是最安全/最容易的:
$ git add foo.sql
$ git commit -m "Fixed foo.sql"
This just commits the file foo.sql. Before the commit you can do:
这只是提交文件 foo.sql。在提交之前,您可以执行以下操作:
$ git status
to confirm that only the required file will be committed (it will list the other modified files separately, but they will not be "staged" for the next commit).
确认只提交所需的文件(它将单独列出其他修改过的文件,但不会为下一次提交“暂存”)。
回答by Mot
回答by Tim Bodeit
With current versions of git you can also do:
使用当前版本的 git,您还可以执行以下操作:
git commit <filename>
This will commit everything in that file and only that file. What is currently staged to the index doesn't matter.
这将提交该文件中的所有内容,并且仅提交该文件。当前上演到索引的内容无关紧要。
Some versions of git require additional arguments to be placed before the filename. This includes -m <message>
.
某些版本的 git 需要在文件名之前放置额外的参数。这包括-m <message>
.
回答by johnny
If you can use gitbash or something similar, use git add <filename>
.
如果您可以使用 gitbash 或类似的东西,请使用git add <filename>
.