我在主分支上做了一些更改。现在,我要在几次提交中保留我的更改。
比方说,这是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
?我曾考虑过创建一个新分支,然后将所做的更改移至该分支,然后提交它们,但是我不知道如何仅移动这些文件的一部分。
答案 0 :(得分:2)
执行该操作,就像执行其他任何提交一样:
git add ../java
git commit -m "Updated file1 and file2"
git add package*.json
git commit -m "Updated package.json"
答案 1 :(得分:1)
只需将文件添加到要提交的索引中即可。
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"