将单个干净的提交/分支推送到远程

时间:2020-05-04 19:47:25

标签: git push branch git-remote

我有一个具有大量历史记录,多个分支等的存储库“ A”。我想进行一次简单,有效的提交,并将其用作新的远程“ B”的起始位置,以便只有在远程“ B”上可见的一次提交,并且从那里我可以理想地推送到“ B”和“ A”,甚至更好的是让“ B”的分支跟踪源“ A”

2 个答案:

答案 0 :(得分:1)

检出代码处于所需状态的提交,并创建一个 orphan 分支,当您提交该代码时,将导致无父母的提交:

git checkout --orphan clean-branch
git commit -a
git push B clean-branch

然后,再次检出常规分支并继续在那里工作。每当您想再次同步时,请执行以下操作:

git reset --soft clean-branch
git commit
git push B clean-branch

软重置会保留您的工作目录,但会保留它,以便下次提交将在指定的分支上。

(我不声明此工作流程是否是一个好主意。)

答案 1 :(得分:1)

通常,当您在分支“ master”下创建新分支时,您将继承其提交历史记录。 import pygame import random import os from math import floor, ceil screen_width = 1400 screen_height = 700 square_size = 20 pygame.init() class Map: def __init__(self, world, names): os.environ['SDL_VIDEO_CENTERED'] = '1' self.screen = pygame.display.set_mode([screen_width, screen_height]) pygame.display.set_caption("Map") # creates a dictionary of random colors to represent each character colors = {} for item in names.keys(): if item not in colors.keys(): colors[item] = [random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)] # creates a new map with the square sprites in which will form the map self.map = [] self.square_group = pygame.sprite.Group() for i in range(len(world)): self.map.append([]) for j in range(len(world[i])): square = Square(colors[str(world[i][j])], i, j) self.map[i].append(square) self.square_group.add(square) self.x = 0 self.y = 0 self.draw(self.screen) pygame.display.flip() def draw(self, screen): self.square_group.draw(screen) def observe(self): has_quit = False mouse_down = False original_x = 0 original_y = 0 while not has_quit: for event in pygame.event.get(): if event.type == pygame.MOUSEBUTTONDOWN and not mouse_down: original_x, original_y = pygame.mouse.get_pos() mouse_down = True # quits if the user clicks outside the map (probably a bad way of doing it) if not 0 <= original_x <= screen_width or not 0 <= original_y <= screen_height: has_quit = True pygame.QUIT() # scrolls the map around while the user is holding the mouse down while mouse_down: final_x, final_y = pygame.mouse.get_pos() new_x = (final_x - original_x) / square_size + self.x new_y = (final_y - original_y) / square_size + self.y original_x = final_x original_y = final_y if new_x > 0: new_x = 0 elif -new_x * square_size > len(self.map) * square_size - screen_width: new_x = screen_width / square_size - len(self.map) if new_y > 0: new_y = 0 elif -new_y * square_size > len(self.map[0]) * square_size - screen_height: new_y = screen_height / square_size - len(self.map[0]) for i in range(floor(-max(self.x, new_x)), ceil(-min(self.x, new_x) + screen_width/square_size)): for j in range(floor(-max(self.y, new_y)), ceil(-min(self.y, new_y) + screen_height/square_size)): self.map[i][j].sync(square_size, new_x*square_size, new_y*square_size) self.square_group.draw(self.screen) pygame.display.flip() self.x = new_x self.y = new_y # checks whether the user has stopped holding their mouse down for event in pygame.event.get(): if event.type == pygame.MOUSEBUTTONUP: mouse_down = False # class for the squares on the map class Square(pygame.sprite.Sprite): def __init__(self, colour, x, y, size=square_size): super().__init__() self.colour = colour self.x = x self.y = y self.image = pygame.Surface([size, size]) self.rect = self.image.get_rect() pygame.draw.rect(self.image, self.colour, [0, 0, size, size]) self.sync(size, 0, 0) # makes sure the square is in the correct position and is the correct size def sync(self, size, map_x, map_y): self.rect = self.image.get_rect() self.rect.x = self.x * size + map_x self.rect.y = self.y * size + map_y pygame.transform.scale(self.image, (size, size)) (或断开连接)分支是一个例外。孤儿分支与主分支的提交没有父子关系。 大多数提交都有一个父提交,一个明显的例外是没有父提交的根提交。创建orphan将保留分支所基于的工作树,但没有祖先提交。

#创建新分支 b 并切换到该分支:orphan branch

#创建一个 README.md 文件:git checkout --orphan b

#将README.md文件添加到git:touch README.md;

#对此分支进行首次提交git add README.md;

#推送分支 b ,并将上游分支设置为分支 a git commit -m 'orphan branch initial commit';


上游分支定义了本地远程分支(也称为远程跟踪分支)在远程存储库上跟踪的分支。通过编写git push --set-upstream a b;

来检查跟踪分支