我想提交除一个文件以外的所有文件。我可以使用GitHub for Windows客户端执行此操作,还是需要使用命令行?如果我需要使用命令行,我该如何使用它?
据我所知,如果不使用git shell /命令行,这是不可能的。在Git Shell中,您有几种选择。所有这些都会产生略微不同的结果。
git add .
git reset filename
git commit -m "commit message"
第一个命令将所有文件添加到暂存区域。 Then the second command removes the one file from the staging area. This means the file is not added in the commit but the changes to it are preserved on your local drive.git update-index --assume-unchanged
:
`git update-index --assume-unchanged filename`
如果您在本地更改文件,则在执行添加所有文件(如git add .
)的操作时,它将不会添加到暂存区域。 When, after some time, you want to commit changes to the file again, you can run git update-index --no-assume-unchanged filename
to stop ignoring the changes..gitignore
文件。 To ignore a file named filename
you create, or edit, a file called .gitignore
. Put filename
on a line of its own to ignore that file.现在执行git add .
时文件未添加到临时区域。备注:如果文件已经签入,则必须将其从存储库中删除才能真正开始忽略它。执行以下操作即可:
`git rm --cached filename`
The --cached
option specifies that the file should only be removed from the index.本地文件,无论是否改变,都将保持不变。您可以添加.gitignore
文件并提交以使其在具有相同存储库的其他计算机上被忽略。.git/info/exclude
中。 .git
目录通常是隐藏的,但您可以通过更改文件夹选项使其可见。与.gitignore
文件一样,如果文件已由先前的提交签入,则必须执行git rm --cached filename
。一些说明:
filename
更改为要排除的文件的实际名称。filename
的地方替换目录名来做到这一点。Open in Git Shell
选项。现在,您位于git存储库的根目录下,您可以开始执行此答案中显示和描述的命令。我会做以下事情:
git add .
git checkout filename
git commit -m "commit message"
第一行添加列表中的所有文件,第二行删除您指定的文件,其中“filename”应该是您在提交时不想要的文件的名称。
要么
git checkout filename
git commit -am "commit message"
git commit -am添加文件并同时发出提交消息。
如果您需要删除您在上一个文件中所做的更改:
git stash -u
您只需创建一个.gitignore文件,并添加要在其中排除的文件的名称。