简体   繁体   English

如果队友已经推动了我如何安全地进行更改

[英]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 ,然后commitrebase 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 ,而不是 fetchmergepull ),但这只是个人喜好。

  1. git fetch
  2. git add <files to add>
  3. git commit -m <commit message>
  4. 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您的更改。

Pulling and merging 拉并合并

  • commit your changes 提交您的更改
  • pull the other changes 拉其他变化
  • fix merge conflicts if there are any 修复合并冲突(如果有)
  • commit 承诺

Stashing 积攒

  • stash your changes 储存您的变更
  • pull the commits from the repo 从仓库中提取提交
  • get back the stash code 取回隐藏代码

Rebasing 垫底

Bill already covered that 条例草案已经涵盖了

branching 分枝

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.

相关问题 GIT:我的队友无法提取我推送的更改 - GIT: My Teammate cannot pull the changes I pushed 如何为上次未按下的提交添加新更改? - How can I add new changes to the last not-pushed commit? 在git上,如何忽略已推送到原始仓库的特定文件夹,将更改推送到部署的仓库? - On git, how would I push changes to my deployed repo ignoring a specific folder that has already been pushed to my origin repo? 进行了git commit,git pull并将我的更改推送到了仓库。 我如何发送对我提交的请求的请求 - did a git commit, git pull and pushed my changes to the repo. How can i send a Pull request for the one that i committed 我如何才能发现已被推送的提交已被修改然后再次被推送? - How can I discover that a commit that has been pushed was amended and then pushed again? 在我已经提交更改后,如何将提交分成两部分 - How can I split a commit in two, after I've already committed my changes 我如何将提交推送到已经从本地存储库推送到 git 的 heroku? - How could i push a commit to heroku that has already been pushed to git from local repo? 如何在不破坏队友工作的情况下推送提交? - How do I push a commit without destroying teammate work? 如何安全提交.git目录 - How can I safely commit a .git directory 如果我已经推送了原始提交,如何从提交中恢复--amend? - How do I recover from a commit --amend if I already pushed the original commit?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM