【发布时间】:2018-08-01 10:54:10
【问题描述】:
当我从事使用控制系统 git 的项目时,每次我想提交然后将我的修改推送到 git pull 之前。但是我遇到的问题是,在很多时候 git 禁止我拉,因为我应该在提交本地更改之前。我以前做的是我有另一个干净的 git 存储库,我不直接修改它,但是当我需要时,我将它用于 git pull 然后使用 meld 将我的修改合并到它,从我工作的另一个存储库.但我认为这种方式不是最好的,浪费了很多时间,是时候优化它了。我想做的是创建另一个本地分支“work_branch”并将我的修改提交到本地,然后将提交从“work_branch”合并到“master”,然后在拉取后推入master。所以场景应该是这样的:
git branch work_branch
git checkout work_branch
#modify in branch work_branch
git commit
git add <files list>
git commit -m "fixes branch work" #local commit
gitk ==> get the id of "fixes branch work" commit (example: 5b099287c229e16c24bfcdbfd6fba384cfe165e6)
git checkout master
git pull
git cherry-pick 5b099287c229e16c24bfcdbfd6fba384cfe165e6 #merge "fixes branch work" commit from work_branch to master branch
git push
我遇到的问题是在第三步之后(#modify in branch work_branch),分支work_branch中的每个modif都是master分支查看的,但是我想要的是master分支只能从work_branch看到合并的commit在git cherry-pick 命令之后。
有没有办法改进我的解决方案。或者有没有其他好方法来优化使用 git。
【问题讨论】:
-
搜索“git stash”。
-
为什么不能在拉取之前提交? Git 旨在处理这种情况。或者更确切地说,为什么你必须在提交之前拉动?为什么你觉得这是要走的路?
-
您希望只看到合并提交,而不是您在
work_branch上所做的其他提交?