简体   繁体   English

选定文件上的git存储库提交

[英]git repository on selected files commit

I am having a problem in git repository on selected files commit. 我在选定文件提交的git存储库中遇到问题。

As in SCM or SVN if I have modified 4 files.But want to commit only two then I can easily commit the selected files only. 与SCM或SVN一样,如果我修改了4个文件,但是只想提交两个文件,那么我可以轻松地仅提交所选文件。

But in git when using cmd: git commit -a.It is going to commit all modified files. 但是在git中使用cmd时:git commit -a。它将提交所有修改过的文件。 If use cmd like git commit filename filename.It is not working. 如果使用像git commit filename filename这样的cmd,它将不起作用。

So any help how to commit only selected files in git. 因此,如何在git中仅提交选定文件的任何帮助。

Don't use git commit -a if you don't want to commit everything - since -a is "commit all". 如果您不想提交所有内容,请不要使用git commit -a因为-a是“全部提交”。

Instead, use git add <filename> to add the files you want to commit, and the just git commit . 而是使用git add <filename>添加要提交的文件,然后添加git commit

For example, if you have three files foo , bar , and baz , and you want to only commit the changes to foo and bar , then do: 例如,如果您有三个文件foobarbaz ,并且只想将更改提交到foobar ,那么请执行以下操作:

git add foo
git add bar
git commit

(You could also do git add foo bar to add both files in a single command.) (您也可以执行git add foo bar以在单个命令中添加两个文件。)

Now it is working. 现在正在工作。

From the git doc : 从git doc

git commit ... <file> ...​
When files are given on the command line, the command commits the contents of the named files, without recording the changes already staged. 当在命令行上提供文件时,该命令将提交命名文件的内容,而不记录已进行的更改。 The contents of these files are also staged for the next commit on top of what have been staged before. 这些文件的内容也会在之前已执行的内容的基础上,为下一次提交而进行。

To commit only some (added!) files do this: 要仅提交一些(添加!)文件,请执行以下操作:

git commit sample_file1.txt sample2.php file3.cs

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

相关问题 尝试创建git存储库并提交文件到它,但是没有运气 - Trying to create git repository and commit files to it but with no luck 是否可以在 git 存储库之外添加和提交文件? - Is it possible to add and commit files outside of a git repository? 如何在Git中提交和推送所选文件,但不是全部 - How to commit & push selected files but not all in Git Git push命令可推送本地存储库中不存在的已删除文件或提交 - Git push command pushes deleted files not present in local repository or commit GIt:使用BFG从存储库中删除了几个文件,并且提交差异很大 - GIt: Removed several files from repository with BFG and there are enormous commit diffs 如何列出添加到GIT存储库第一次提交的所有文件? - How to list all files added to the first commit of a GIT repository? 在Git存储库中要提交或忽略什么类型的文件? - What type of files to commit versus ignore in a Git repository? Git:从另一个提交覆盖存储库中的所有文件 - Git: overwrite all files in a repository from another commit 将文件还原到特定的提交,而不会影响本地存储库git - Revert files to a specific commit without affecting local repository git 通过 Python 获取 Git 存储库文件的最后提交时间? - Get time of last commit for Git repository files via Python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM