5

git 问题咨询

 2 years ago
source link: https://www.v2ex.com/t/845078
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

V2EX  ›  程序员

git 问题咨询

  JadePenG · 4 小时 0 分钟前 · 531 次点击

git 用的比较少, 所以来询问一下大佬们,我遇到如下场景有什么方式可以处理。 目前项目只有一个分支,master 分支。 假如我目前在开发当前项目的 V1.2 版本,但是 V1.1 版本有 BUG 时,我需要修改对应的代码。 但是 V1.2 版本的新功能不可能在一次 BUG 修复中就发布出来。那么此时我应该怎么处理 V1.2 版本新功能的代码呢?

可以不通过新建一次分支的情况下处理嘛。 [这是重点哦]

10 条回复    2022-04-06 00:12:12 +08:00

fiypig

fiypig      3 小时 54 分钟前 via iPhone

dvsilch

dvsilch      3 小时 48 分钟前

在本地新建一个分支推到 master 都不行吗?

gengchun

gengchun      3 小时 47 分钟前

用分支

https://git-scm.com/book/en/v2/Git-Branching-Branches-in-a-Nutshell


Because a branch in Git is actually a simple file that contains the 40 character SHA-1 checksum of the commit it points to, branches are cheap to create and destroy. Creating a new branch is as quick and simple as writing 41 bytes to a file (40 characters and a newline).

pagxir

pagxir      3 小时 45 分钟前 via Android

这个跟 git 没关系吧,这个是分支管理的问题,即使你换成 SVN 也一样需要考虑怎么去管理分支,什么时候合并分支

marat1ren

marat1ren      3 小时 43 分钟前 via iPhone

假设 v1.2 还是在你的本地 master ,那么你可以先把 v1.1 的修复 push 到 master 上去。然后 rebase 有修复的 master 。第二种情况,如果 master 上已经是 v1.2 了,那只能建议新建一个基于 v1.1 的 branch ,把修复 push 到这个新 branch 上。

CEBBCAT

CEBBCAT      3 小时 39 分钟前 via iPhone

你要是实在想问,那么 stash 可以解决你的问题,rebase+checkout 也许也可以

但是你这么做,用的还是 git 吗?以上操作有较高的丢失代码的风险。你未来开发到 2.0 的时候,又该要怎么修复 1.1 的 bug 呢?

nightwitch

nightwitch      2 小时 50 分钟前

先从你当前远程的那个 commit id 分叉一个分支 v1.1 ,然后修复 bug ,push 到远端。
本地的 master 有一堆 v1.2 的代码还没实现完,rebase 到修复完 bug 的分支上。

christin

christin      2 小时 43 分钟前 via iPhone

只有一个分支万一出问题怎么办 建议多开几条分之,又不要钱

msg7086

msg7086      1 小时 2 分钟前

不新建分支还用什么 git 。你就算是新建文件夹( 1 )那也是分支啊。

zkd8907

zkd8907      47 分钟前

在一些管理的方式下 v1.1 应该是一个 tag ,它会指向到 master 上的一个 commit 。如果 v1.2 在 master 上开发并且又要修改 v1.1 的 bug ,可以直接从 v1.1 的 tag 拉一个新的 hotfix 分支进行开发修复,修复后通过打 v1.1.1 tag 进行发布,同时将 master 也 rebase 到 v1.1.1 上,这样 master 也会包含这个改动。

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK