简体   繁体   English

何时提交并推送到工作的远程 git 存储库?

[英]When to commit and push to a working remote git repository?

My question is not related to an obvious coding problem but after 3 years of experience working on different projects and using Gitlab & Github.我的问题与明显的编码问题无关,但在从事不同项目工作 3 年并使用 Gitlab 和 Github 之后。 I am still not sure when to commit & push the code implemented so far to its original repository.我仍然不确定何时提交并将迄今为止实现的代码推送到其原始存储库。

To be clear,要清楚,

  • shall we do a new push whenever we finish a certain task?当我们完成某项任务时,我们是否应该进行新的推送?

  • Or maybe whenever we write a certain code and we are sure that it's not going to be changed?或者也许每当我们编写某个代码并且我们确定它不会被更改时?

  • Or as usually I do at the end of a working day if the task does not finish yet (just to save the work remotely) as a [WIP] push!或者,如果任务尚未完成(只是为了远程保存工作),我通常会在工作日结束时将工作作为 [WIP] 推送!

  • Or...或者...

Is there any link or resource for similar thoughts?有没有类似想法的链接或资源?

Create a commit every time you accomplish something每次完成某事时创建一个提交

Think about rock climbers.想想攀岩者。 They climb up a vertical rock wall, every inch is a difficult battle.他们爬上一堵垂直的岩壁,每一寸都是一场艰苦的战斗。 Every so often, they stop to hammer a spike into the rock and attach a rope.每隔一段时间,他们就会停下来在岩石上钉一根钉子并系上一根绳子。 Why do they do this?他们为什么这样做呢?

So they don't die if they lose their grip and fall.因此,如果他们失去抓地力并跌倒,他们不会死。

There are many reasons to use source control, but this is one of the biggest ones that matters to the developer.使用源代码控制的原因有很多,但这是对开发人员最重要的原因之一。

Each of us is often working on the hardest task we are capable of, which means the work is hard.我们每个人都经常从事我们能够完成的最艰巨的任务,这意味着工作很辛苦。 When the work is hard we are likely to make mistakes, to suddenly find ourselves in strange territory and not know how to get back to safety.当工作很辛苦时,我们很可能会犯错误,突然发现自己处于陌生的境地,不知道如何回到安全的地方。 An extremely common scenario is to have difficulty creating a first working version of something, to finally accomplish it and demo it for your bosses, then accidentally break it when you go back to your desk to clean up the code or finish the task.一个非常常见的情况是难以创建某个东西的第一个工作版本,最终完成它并为你的老板演示它,然后当你 go 回到你的办公桌清理代码或完成任务时意外破坏它。 I have seen people spend waste days trying to get back to the point they were at when they did the demo.我见过人们浪费时间试图回到他们做演示时的状态。

A commit is like a map marker you can teleport to from anywhere.提交就像一个 map 标记,您可以从任何地方传送到该标记。 No matter how lost you get, no matter how badly you break things, you can always go back to the way things were at that commit.无论你多么迷失,无论你破坏的东西有多严重,你总是可以 go 回到那个提交时的状态。

Commits are free.提交是免费的。 It costs nothing to create a commit.创建提交不需要任何成本。 The rock climber only has 20 spikes in her bag.这位攀岩者的包里只有 20 个钉子。 You have an infinite number 1 , Commit early, commit often!!你有一个无限的数字1 ,尽早提交,经常提交!!

Write decent commit messages so you can tell them apart: they are notes to yourself and your life might depend on them sooner than you think.写出体面的提交信息,这样你就可以把它们区分开来:它们是给你自己的笔记,你的生活可能比你想象的更早依赖它们。

Here is a not-terrible example to illustrate how small are the things that count as "milestones":这是一个不可怕的例子来说明算作“里程碑”的事情有多小:

1. got the form fields laid out right
2. added the submit button
3. stubbed validation hook for form submission
4. installed validation library and wired it into validation hook
5. defined custom validation rules for the address fields
6. wired up display of validation failures
7. fixed layout of fields after error messages messed it up
8. replaced validation library with the version they told me to use
...

If you are working on your own private branch -- which you should be -- commits are also secret things you can clean up later before anybody else sees them.如果你在自己的私有分支上工作——你应该这样做——提交也是秘密的东西,你可以在其他人看到它们之前清理它们。 If you are embarrassed that it took you 25 commits / 25 attempts / 25 steps to do something that is "easy," you can edit your commit history before you submit it for code review.如果您对花费 25 次提交 / 25 次尝试 / 25 步来完成“简单”的事情感到尴尬,您可以在提交代码审查之前编辑您的提交历史。 Some places even require you to squash your history down when you're finished -- which is no reason to not create lots of commits while you are doing the work.有些地方甚至要求你在完成后压缩你的历史记录——这不是你在工作时不创建大量提交的理由

I usually create 25 - 50 commits per day.我通常每天创建 25 - 50 个提交。 I spent a month working on a big feature and had 269 commits at the end.我花了一个月的时间开发一个大特性,最后提交了 269 次。 Nobody saw those.没有人看到那些。 When I was finished, I squashed it all down to basically 1 commit.完成后,我将其全部压缩为基本上 1 次提交。 Nobody knows it took me ~300 tiny steps to climb that mountain.没有人知道我花了大约 300 小步才能爬上那座山。 All they know is that I made it to the top and planted their silly flag, and that's all they care about.他们只知道我登上了顶峰并插上了他们愚蠢的旗帜,这就是他们所关心的。 You are the person who gets hurt if you fall.如果你跌倒,就是那个受伤的人。

How often should you commit?你应该多久提交一次? How much of your own work are you willing to recreate from scratch the next time you make a mistake that you can't figure out?下次你犯了一个你无法弄清楚的错误时,你愿意从头开始重新创作多少自己的作品? Are you so amazing at programming that you can sling code for weeks without any missteps, without any false starts, without having any ideas that failed to work out?您是否在编程方面如此出色,以至于您可以连续数周编写代码而没有任何失误,没有任何错误的开始,没有任何失败的想法? Even if the answer is "yes, puny mortal, I am the god of programming,"?即使答案是“是的,微不足道的凡人,我是编程之神”? do you really gain anything from playing by those iron-man rules?遵守那些铁人规则,你真的有收获吗?

Your safety net is made up of commits.您的安全网由提交组成。 Don't skimp on materials.不要吝啬材料。


1 It turns out there is a limit to the number of commits. 1事实证明,提交的数量有限制的。 According to this answer , you can have at most 1.4✕10 48 commits in one repository.根据这个答案,您最多可以在一个存储库中进行 1.4✕10 48 次提交。 That's plenty.这已经足够了。 And if you run out, you'll become famous: the first and only programmer to outgrow git.如果你用完了,你就会成名:第一个也是唯一一个超越 git 的程序员。

usually I do at the end of a working day if the task does not finish yet (just to save the work remotely) as a [WIP] push!通常,如果任务尚未完成(只是为了远程保存工作),我会在工作日结束时将工作作为 [WIP] 推送!

No need for that: you create a feature branch where you are the only one working on it, and you can commit/push at any time.不需要这样做:您创建一个功能分支,您是唯一一个在其中工作的人,您可以随时提交/推送。
You will be able to rebase/reorder/squash commits later when you want to make a pull request to the target branch you want to contribute..当您想向您想要贡献的目标分支发出拉取请求时,您将能够稍后重新设置/重新排序/压缩提交。

暂无
暂无

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

相关问题 git 命令(推、拉、克隆)不适用于 android studio - 谷歌云存储库 - git commands(push, pull, clone) not working on android studio - google cloud repository AWS codecommit 不适用于 git-remote-codecommit - AWS codecommit not working with git-remote-codecommit 将存储库从一个 git 实例连同所有提交和分支历史记录一起移动到另一个实例 - Moving repository from one git instance to another along with all commit and branch histories Git 的提交历史中没有合并提交 - No merge commit in the commit history in Git ssh:无法解析主机名 git:名称或服务未知致命:无法从远程存储库读取 - ssh: Could not resolve hostname git: Name or service not known fatal: Could not read from remote repository 使用谷歌云 SDK Windows 10 上的身份验证方法获取 Git 推送到谷歌云源存储库的权限被拒绝(公钥) - Get Permission denied (publickey) for Git push to Google Cloud Source Repository with Google Cloud SDK authentication method on Windows 10 尝试推送到 git 实验室时,“确保在 git 中配置了 'user.email' 和 'user.name'” - "Make sure you configure your 'user.email' and 'user.name' in git" when trying to push to git lab 无法推送到 git 中的开发分支 - Failing to push to a dev branch in git 无法将代码推送到 CodeCommit 存储库 - Could not push code to the CodeCommit repository 当 gitlab CI/CD 触发时,如何通过 git 而不是从预定义的变量获取提交标签 - How to get the commit TAGS, via git and not from predefined vars, when gitlab CI/CD triggers
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM