[英]How can I safely commit my changes if the teammate has already pushed
I have the following situation. 我有以下情况。 I have worked on some files and didn't commit/push. 我已经处理了一些文件,没有提交/推送。 My teammate has worked on some other files (different from mine) and already committed/pushed his changes. 我的队友还处理了其他文件(与我的文件不同),并且已经提交/推动了他的更改。 How can I safely pull his changes, and then commit and push mine? 我怎样才能安全地提取他的更改,然后提交并推送我的? Thank you in advance. 先感谢您。
There are several different ways you could handle this. 您可以通过几种不同的方式来处理此问题。 You could commit
your changes and then pull
. 您可以commit
更改,然后再pull
。 You could stash
your changes, pull
, and then apply your stash
. 您可以stash
的更改, pull
,然后应用stash
。 You could fetch
first, then commit
and rebase
. 您可以先fetch
,然后commit
并rebase
。 I personally like doing this a little more explicitly (with a fetch
followed by rebase
, instead of a pull
which combines a fetch
with a merge
), but that is just personal preference. 我个人喜欢更明确地执行此操作(先执行fetch
然后执行rebase
,而不是将 fetch
与merge
的pull
),但这只是个人喜好。
git fetch
git add <files to add>
git commit -m <commit message>
git rebase <branch to replay commit onto (ie origin/master)>
The rebase
step will provide you the opportunity to resolve any conflicts, if the other developer and you were working in the same space. 如果其他开发人员和您在同一空间中工作,则重新设置rebase
步骤将为您提供解决所有冲突的机会。
You should then be able to push
your changes. 然后,您应该能够push
您的更改。
Bill already covered that 条例草案已经涵盖了
Create a branch where you commit your changes, switch back to the branch you were at and pull: Move existing, uncommitted work to a new branch in Git 在您提交更改的位置创建一个分支,切换回您所在的分支并拉出: 将现有的未提交的工作移至Git中的新分支
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.