如何在我的分支中只存储多个已更改文件中的一个?
当前回答
类似的情况。做了承诺,意识到这不好。
git commit -a -m "message"
git log -p
根据这些回答,这对我有帮助。
# revert to previous state, keeping the files changed
git reset HEAD~
#make sure it's ok
git diff
git status
#revert the file we don't want to be within the commit
git checkout specs/nagios/nagios.spec
#make sure it's ok
git status
git diff
#now go ahead with commit
git commit -a -m "same|new message"
#eventually push tu remote
git push
其他回答
git stash push -p -m "my commit message"
-p让我们选择应该隐藏的大块;也可以选择整个文件。
系统将提示您对每个大块执行一些操作:
y - stash this hunk
n - do not stash this hunk
q - quit; do not stash this hunk or any of the remaining ones
a - stash this hunk and all later hunks in the file
d - do not stash this hunk or any of the later hunks in the file
g - select a hunk to go to
/ - search for a hunk matching the given regex
j - leave this hunk undecided, see next undecided hunk
J - leave this hunk undecided, see next hunk
k - leave this hunk undecided, see previous undecided hunk
K - leave this hunk undecided, see previous hunk
s - split the current hunk into smaller hunks
e - manually edit the current hunk
? - print help
在这种情况下,我使用gitadd-p(交互式)、gitcommit-m blah,然后在必要时存储剩余的内容。
git add . //stage all the files
git reset <pathToFileWillBeStashed> //unstage file which will be stashed
git stash //stash the file(s)
git reset . // unstage all staged files
git stash pop // unstash file(s)
一个复杂的方法是首先提交所有内容:
git add -u
git commit // creates commit with sha-1 A
重置回原始提交,但从新提交中签出_one_file:
git reset --hard HEAD^
git checkout A path/to/the_one_file
现在,您可以存储_one_file:
git stash
通过将提交的内容保存在文件系统中并重置为原始提交来进行清理:
git reset --hard A
git reset --soft HEAD^
是的,有点尴尬。。。
类似的情况。做了承诺,意识到这不好。
git commit -a -m "message"
git log -p
根据这些回答,这对我有帮助。
# revert to previous state, keeping the files changed
git reset HEAD~
#make sure it's ok
git diff
git status
#revert the file we don't want to be within the commit
git checkout specs/nagios/nagios.spec
#make sure it's ok
git status
git diff
#now go ahead with commit
git commit -a -m "same|new message"
#eventually push tu remote
git push
推荐文章
- 为什么我需要显式地推一个新分支?
- 如何撤消最后的git添加?
- Rubymine:如何让Git忽略Rubymine创建的.idea文件
- Gitignore二进制文件,没有扩展名
- Git隐藏错误:Git隐藏弹出并最终与合并冲突
- 了解Git和GitHub的基础知识
- 没有。Git目录的Git克隆
- Git与Mercurial仓库的互操作性
- 忽略git中修改(但未提交)的文件?
- “git restore”命令是什么?“git restore”和“git reset”之间有什么区别?
- Git合并与强制覆盖
- Git拉另一个分支
- 在Bash命令提示符上添加git分支
- 如何更改Git日志日期格式
- git pull -rebase和git pull -ff-only之间的区别