[英]Git: Commit a subset of modified/untracked files
我在主分支上做了一些更改。 现在,我要在几次提交中保留我的更改。
假设这是git status
的结果:
On branch master
Your branch is up-to-date with 'origin/master'.
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: ../../../.gitignore
modified: ../java/file1.java
modified: ../java/file2.java
modified: package-lock.json
modified: package.json
modified: src/index.js
Untracked files:
(use "git add <file>..." to include in what will be committed)
src/components/authentication/
src/components/route/
src/helpers/
如何在一次提交中提交file1
和file2
,在下一次提交中package.json
和package-lock.json
? 我曾想过创建一个新分支,然后将更改移动到该分支,然后提交它们,但是我不知道如何仅移动这些文件的一部分。
像执行其他任何提交一样执行此操作:
git add ../java
git commit -m "Updated file1 and file2"
git add package*.json
git commit -m "Updated package.json"
只需将文件添加到要提交的索引中即可。
git add ../java/file1.java
git add ../java/file1.java
git commit -m "First commit"
git add package-lock.json
git add package.json
git commit -m "Second commit"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.