简体   繁体   English

不能推或拉。 (Git / SourceTree)

[英]Can't push or pull. (Git / SourceTree)

Very new to Git, and I am currently using SourceTree. 对Git来说很新,我目前正在使用SourceTree。

I have found myself in a very interesting situation that I cannot seem to get myself out of. 我发现自己处于一个非常有趣的境地,我似乎无法摆脱困境。 I cannot seem to pull, or push code. 我似乎无法拉动或推动代码。 I seem to be 2 commits ahead, and 2 commits behind, 我似乎提前2次提交,2次提交,

as illustrated here. 如图所示。 I am just trying to get current, so I can pull down all recent code, and continue to work. 我只是想获得最新信息,所以我可以删除所有最近的代码,并继续工作。 I am not sure how to proceed. 我不知道该怎么办。

I don't want to lose the work for my commits, but I would if it really mattered because they are minor. 我不想为我的承诺丢失工作,但如果真的很重要,我会这样做,因为它们很小。

What is the easiest and most appropriate route to take in order to get the branch up to date and in sync with my local branch? 为了使分支更新并与我的本地分支同步,最简单,最合适的路线是什么?

If you've no uncommitted changes 如果您没有未提交的更改

Just PULL first. 先拉。 SourceTree will ask you to solve merge conflicts if there are any. SourceTree会要求您解决合并冲突,如果有的话。 Then PUSH your changes. 然后推你的改变。

If you've uncommitted changes 如果你有未提交的更改

Git has a feature called stashing to save your unfinished changes. Git有一个名为stashing的功能来保存未完成的更改。 In SourceTree, do the following steps: 在SourceTree中,执行以下步骤:

  1. Select your repository, click on Repository in the main menu and then on Stash Changes 选择您的存储库,单击主菜单中的Repository ,然后单击Stash Changes
  2. Give your stash a name like "uncommitted feature" and make sure the checkbox is unselected 为您的存储添加“未提交功能”之类的名称,并确保未选中该复选框
  3. Now pull all the latest changes 现在拉出所有最新的变化
  4. In the tree-menu left to your files you find a category Stashes , expand it and search for your created stash 在文件左侧的树状菜单中,您可以找到一个类别Stashes ,展开它并搜索您创建的藏匿处
  5. Right click on in and select "apply stash" 右键单击并选择“apply stash”

Resolve merge conflicts if there are any. 如果有,则解决合并冲突。 Now you should be able to commit and push like you used to. 现在你应该像以前那样提交和推送了。

People probably have made updates into the project you've cloned (that explains the commits behind) and you've also made commits since you've cloned, and didn't pushed yet (and that explains the commits ahead). 人们可能已经对您克隆的项目进行了更新(这解释了后面提交的内容),并且您自克隆以来也做过提交,并且还没有推送(这解释了未来的提交)。 What you have to do is: 你要做的是:

reseting your commits, but keeping the changes by using git reset --soft HEAD^ 重置您的提交,但使用git reset保留更改--soft HEAD ^

stash your changes by using git stash 使用git stash存储您的更改

and than, 然后,

pull things people updated on your head branch using git pull origin branchName 使用git pull origin branchName在你的头部分支上更新人物

If you didn't stashed, you will probably get conflicts now, because the system is not smart enough to know whats the priority: what you have changed or what people from other branches changed. 如果你没有被隐藏,你现在可能会遇到冲突,因为系统不够智能,无法知道什么是优先级:你改变了什么或者其他分支机构的人改变了什么。 That might be not so easy to solve so i strongly recommend you to stash your changes before doing 'pull'. 这可能不是那么容易解决,所以我强烈建议你在做“拉”之前隐藏你的更改。

Now, assuming that you've pulled new things into your branch, 现在,假设你已经把新东西带进了你的分支,

get your updates back on it by doing: git stash apply 通过执行以下操作获取您的更新: git stash apply

Now you have no commits ahead but your changes are waiting to be committed, 现在你没有提交,但是你的更改正在等待提交,

so separately, make your commits and than use: git push origin branchName 所以单独进行提交而不是使用: git push origin branchName

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM