只推送一个文件到 GIT
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24586433/
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
Pushing only one file to GIT
提问by BentCoder
Before I do mistake, I need to know what I'm about to do is correct. I did some researches but still want make sure because I'm new to GIT and scared of messing whole project. Yes there are a lot of examples but I'm confused. That's all.
在我犯错之前,我需要知道我将要做什么是正确的。我做了一些研究,但仍然想确定,因为我是 GIT 的新手,害怕弄乱整个项目。是的,有很多例子,但我很困惑。就这样。
I have 3 files in local GIT and just want to commit one of them and push it to live GIT. So are these steps correct?
我在本地 GIT 中有 3 个文件,只想提交其中一个并将其推送到实时 GIT。那么这些步骤正确吗?
WHAT I THINK I SHOULD DO !!!
我认为我应该做什么!!!
sudo git add web/js/admin/design.js
sudo git commit -m 'Bug fix'
sudo git push origin sprint-6
GIT STATUS:
吉特状态:
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: src/Hello/AdminBundle/Controller/DesignController.php
modified: web/js/admin/design.js
Untracked files:
(use "git add <file>..." to include in what will be committed)
src/Hello/AdminBundle/Utility/DesignPublisher.php
no changes added to commit (use "git add" and/or "git commit -a")
回答by René H?hle
You commit only files that are added to the repository. So if you need only one file then add only the one file.
您只提交添加到存储库的文件。因此,如果您只需要一个文件,则只需添加一个文件。
git add src/Hello/AdminBundle/Controller/DesignController.php
And then commit it. Files that are untracked are not included in the repo. There you have to add it first.
然后提交。未跟踪的文件不包含在 repo 中。在那里你必须先添加它。
回答by Zacrath
It looks correct to me but if you want to be sure you can run git push
with the --dry-run
option (-n
for short).
在我看来它是正确的,但是如果您想确保可以git push
使用该--dry-run
选项(-n
简称)运行。
If you make a mistake you can revert the commit and try again.
如果你犯了错误,你可以恢复提交并重试。
回答by Sumit Verma
If we want to commit and push only a single file out of all modified/new files, we need to commit that particular file first. Here are the steps to commit and push a single file:
如果我们只想提交和推送所有修改/新文件中的一个文件,我们需要先提交该特定文件。以下是提交和推送单个文件的步骤:
Commit single file:
git commit -m 'your comment' path/to/your/file.txt
Push file to git:
git push remote-name current-branch-name
提交单个文件:
git commit -m 'your comment' path/to/your/file.txt
将文件推送到 git:
git push remote-name current-branch-name