我如何只提交一些文件? [英] How do I commit only some files?

查看:91
本文介绍了我如何只提交一些文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个项目。一个是官方项目,第二个是轻微的修改(添加了一些文件)。我创建了新的分支,并且向它们添加了新的文件。但是在开发过程中,两个分支公用的一些文件被改变了。



我如何只提交这些文件?

解决方案

我想你想将更改提交到一个分支,然后使这些更改在另一个分支中可见。



您只提交更改后的文件:



在git中,您应该在更改分支时在HEAD之上没有任何更改。

  git commit [有些文件] 

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

  git add [某些文件]#将[某些文件]添加到暂存区域
git add [更多文件]#添加[更多文件]到临时区域
git commit#commit [一些文件]和[一些更多文件]

如果您想在两个分支上提供该提交,请执行

  git stash#删除HEAD中的所有更改并将它们保存到其他地方
git checkout< other-project> #改变分支
git cherry-pick< commit-id> #从ANY分支中选择一个提交并将其应用到当前的
git checkout< first-project> #转到另一个分支
git stash pop#再次恢复所有更改


I have two projects. One is the "official" project and the second is a light modification (some files added). I created new branch and I put new files to them. But in during development some files common to both branches is changed.

How do I commit only these files?

解决方案

I suppose you want to commit the changes to one branch and then make those changes visible in the other branch. In git you should have no changes on top of HEAD when changing branches.

You commit only the changed files by:

git commit [some files]

Or if you are sure that you have a clean staging area you can

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]

If you want to make that commit available on both branches you do

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

这篇关于我如何只提交一些文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆