简体   繁体   English

git 如何提交和推送?

[英]How to git commit and push?

I must be missing something, almost always when I'm about to push my commit I'll get blocked because somebody else pushed a commit just before me and my changes (my commit) is not based on the tip of the remote any more.我必须遗漏一些东西,几乎总是当我要推送我的提交时,我会被阻止,因为其他人在我之前推送了一个提交,而我的更改(我的提交)不再基于遥控器的尖端。

At this situation I'll clone the repo again (in another folder) and manually change every file again, commit and hope nobody pushed just before me again.在这种情况下,我将再次克隆存储库(在另一个文件夹中)并再次手动更改每个文件,提交并希望没有人再次推到我面前。 Sometimes it happens though and so I'll clone the repo in another folder a second time and same history repeats.有时它会发生,所以我会第二次将 repo 克隆到另一个文件夹中,并且重复相同的历史记录。

While observing commit history, with my approach I see a clean line, which I like.在观察提交历史时,通过我的方法,我看到了一条我喜欢的干净线。

I noticed other developers in the project are making a merge commit frequently after their own commits.我注意到项目中的其他开发人员在他们自己的提交之后经常进行合并提交。 I guess that's because they are facing the same situation as me (somebody else pushed before and changes are not based on tip anymore) but they are handling the situation in a different way (using a merge commit).我想这是因为他们面临与我相同的情况(之前有人推送过,并且更改不再基于提示),但他们以不同的方式处理这种情况(使用合并提交)。

The problem is that these merge commits (at least the way they are being done) do not introduce anything, they just repeat the changes from previous commit because it seems developer did not issued a pull before push.问题是这些合并提交(至少它们正在完成的方式)没有引入任何东西,它们只是重复先前提交的更改,因为似乎开发人员在推送之前没有发出拉动。 In other words I'll say, commit history line is dirty.换句话说,我会说,提交历史记录线很脏。

I guess the merge commit approach is faster to handle than clone repo again and modify every single file again.我猜合并提交方法比再次克隆 repo 并再次修改每个文件更快。 But commit history line is dirty.但是提交历史行很脏。

Project use just one branch, the master.项目只使用一个分支,master。 And is hosted in a shared folder in local network.并托管在本地网络的共享文件夹中。

I use to do git from command line but these days I'm using https://www.sublimemerge.com almost all the time.我曾经从命令行执行 git 但这些天我几乎一直在使用https://www.sublimemerge.com

How can I improve my commit/push workflow?如何改进我的提交/推送工作流程? Should I use other tools?我应该使用其他工具吗?

For start, it would be better if you did your development on a different branch.首先,如果您在不同的分支上进行开发会更好。 Even if your other developers insist on doing it this way, it doesn't prevent you from branching.即使您的其他开发人员坚持这样做,也不会阻止您进行分支。

  1. Create a new branch.创建一个新分支。
  2. Do your work, committing to this branch as necessary.做你的工作,根据需要提交到这个分支。
  3. Switch to master切换到大师
  4. Pull down new changes.拉下新的变化。
  5. Merge your branch into master将您的分支合并到 master
  6. Push the changes.推动更改。

Alternatively, if you really insist on not using branches and you don't like these merge commits, you could do a rebase.或者,如果你真的坚持不使用分支并且你不喜欢这些合并提交,你可以做一个 rebase。

At this situation I'll clone the repo again (in another folder) and manually change everyfile again,在这种情况下,我将再次克隆存储库(在另一个文件夹中)并再次手动更改每个文件,

This is quite tedious.这是相当乏味的。

Instead, do this:相反,请执行以下操作:

git fetch
git rebase -i origin/master 

This will automatically merge all of the changes that other folks make.这将自动合并其他人所做的所有更改。 In cases where the changes conflict with yours, it'll let you resolve those conflicts.如果更改与您的更改发生冲突,它会让您解决这些冲突。

Then finally然后终于

git push 

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

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