如何仅提交了一些文件?

问题描述 投票:206回答:6

我有两个项目。一个是“官方”的项目,二是光修改(增加了一些文件)。我创造了新的分支,我提出了新的文件给他们。但在发展过程中两个分支常见的一些文件被改变。

如何只提交这些文件?

git git-branch git-commit
6个回答
229
投票

我想你想更改提交到一个分支,然后将这些变更中的其他分支可见。在不断变化的git分支时,你应该有对头顶没有变化。

您只提交修改过的文件是:

git commit [some files]

或者,如果你确信你有一个干净的临时区域,您可以

git add [some files]       # add [some files] to staging area
git add [some more files]  # add [some more files] to staging area
git commit                 # commit [some files] and [some more files]

如果你想犯下可在你做两个分支

git stash                     # remove all changes from HEAD and save them somewhere else
git checkout <other-project>  # change branches
git cherry-pick <commit-id>   # pick a commit from ANY branch and apply it to the current
git checkout <first-project>  # change to the other branch
git stash pop                 # restore all changes again

132
投票

找你要提交的文件列表

$ 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:   file1
modified:   file2
modified:   file3
modified:   file4

将文件添加到分期

$ git add file1 file2

请检查您承诺什么

$ git status

Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

    modified:   file1
    modified:   file2

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:   file3
    modified:   file4

犯了一个提交信息的文件

$ git commit -m "Fixed files 1 and 2"

如果你不小心犯下的错误的文件

$ git reset --soft HEAD~1

如果你想unstage文件并重新开始

$ git reset

Unstaged changes after reset:
M file1
M file2
M file3
M file4

70
投票

你可以犯一些更新的文件,就像这样:

git commit file1 file2 file5 -m "commit message"

20
投票

一些这似乎是“不完整”

群组的人不会知道他们是否应该使用引号等。

加入1个特定的文件示出的位置的路径,以及

git add JobManager/Controllers/APIs/ProfileApiController.cs

提交(记住,提交被当地唯一的,它不影响任何其他系统)

git commit -m "your message"  

推到远程回购

git push  (this is after the commit and this attempts to Merge INTO the remote location you have instructed it to merge into)

其他答案(S)显示您有时会想要做藏匿等。


10
投票

如果您已经上演文件,只需unstage他们:

git reset HEAD [file-name-A.ext] [file-name-B.ext]

然后,通过添加一点他们有点回。


8
投票

假设你更改了多个文件,如:文件1文件2文件3 FILE4 File5

但是你要提交文件1和文件3只变化。

有两种方法可以这样做:1>舞台只有这两个文件,使用:git的补充文件1文件2

然后,提交git的承诺-m“您的信息”

然后推混帐推

2>直接提交

git的承诺文件1文件3 -m“我的信息”

然后推,混帐推

其实,如果我们定期修改文件和分期他们第一种方法是在情况下非常有用 - >大项目,一般住项目。但是,如果我们正在修改文件,而不是分期他们,那么我们可以做直接提交 - >小项目

© www.soinside.com 2019 - 2024. All rights reserved.