gpt4 book ai didi

分阶段更改的 Git 部分提交

转载 作者:IT王子 更新时间:2023-10-29 01:00:52 26 4
gpt4 key购买 nike

我当前的 git status 看起来像这样:

# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: docs/file3.org
# modified: src/main/R/lib.R
#
# 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: docs/file3.org
# modified: src/main/R/lib.R

我想先将暂存 更改提交到docs/file3.org,然后再提交其他暂存更改。但是如果我执行 git commit -m '...' docs/file3.org,它会提交对该文件的暂存和未暂存更改。

有没有简单的方法来做到这一点?或者我是否需要stash我未暂存的更改,取消暂存一个文件,提交另一个,重新暂存,提交,然后stash pop

最佳答案

由于您只需要将分阶段的更改提交到一个文件,您可以只存储,保持索引更改不变,然后再提交文件。

git stash --keep-index #Note that the staged changes also become part of the stash
git commit -m "Commit only one file" docs/file3.org

git commit -m "Commit other staged changed"
git stash pop
# This may raise CONFLICTS since the stash includes the earlier staged changes.
# In case of conflict, the stash is not popped, so you need to drop it explicitly.

关于分阶段更改的 Git 部分提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9020920/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com