首页 > 其他分享 >On Git

On Git

时间:2023-05-26 12:33:05浏览次数:25  
标签:git remote repository tag Git branch new

Start a new code base without history from the existing one

If you want to create a new code base without any history from an existing Git repository, you can follow these steps:

  1. Clone the existing Git repository into a new directory:
    git clone <existing-repo-url> <new-directory>
    Replace with the URL of the existing repository, and with the name of the new directory where you want to create the new code base.

  2. Remove the Git directory from the new directory:

    cd <new-directory>
    rm -rf .git
    

    This will remove the .git directory, which contains the history and metadata for the Git repository.

  3. Initialize a new Git repository in the new directory:
    git init
    This will create a new Git repository in the current directory without any history or metadata from the previous repository.

  4. Add your new files and commit them:

    git add .
    git commit -m "Initial commit"
    

    This will add all new files in the directory to the new Git repository and create an initial commit with the message "Initial commit".

  5. Add a remote repository and push:
    If you want to push your new code base to a remote repository, you can add a new remote and push your changes:

    git remote add origin <new-repo-url>
    git push -u origin master
    

    Replace with the URL of the new remote repository.

Create, merge and push tags to the remote branch

  1. Create a new tag:
    To create a new tag, use the git tag command followed by the tag name. For example, to create a tag named "v1.0.0", run the following command:
    git tag v1.0.0
    This will create a new lightweight tag at the current commit.
  2. Push the tag to the remote branch:
    To push the tag to the remote branch, use the git push command with the --tags option. For example:
    git push --tags
    This will push all tags to the remote branch.
  3. Merge a tag to a branch:
    To merge a tag to a branch, use the git merge command followed by the tag name. For example, to merge the "v1.0.0" tag to the "master" branch, run the following command:
    git merge v1.0.0 master
    This will merge the changes from the tag to the "master" branch.
  4. Push the changes to the remote branch:
    To push the changes to the remote branch, use the git push command with the branch name. For example, to push the "master" branch to the remote repository, run the following command:
    git push origin master
    This will push the changes to the "master" branch to the remote repository.

Remove tags both from local and remote branch

  1. Delete the tag locally:
    To delete a tag locally, use the git tag command with the -d option followed by the tag name. For example, to delete the "v1.0.0" tag locally, run the following command:
    git tag -d v1.0.0
    This will delete the "v1.0.0" tag from your local repository.
  2. Delete the tag from the remote branch:
    To delete a tag from the remote branch, use the git push command with the --delete option followed by the tag name. For example, to delete the "v1.0.0" tag from the remote branch, run the following command:
    git push --delete origin v1.0.0
    This will delete the "v1.0.0" tag from the remote branch.
  3. Remove the tag reference from your local repository:
    To remove the tag reference from your local repository, use the git fetch command with the --prune-tags option. For example:
    git fetch --prune-tags
    This will remove the tag reference from your local repository.

Merge a branch as one commit into another branch

  1. Switch to the branch you want to merge into another branch:
    git checkout target_branch
  2. Merge the source branch into the target branch using the --squash option:
    git merge --squash source_branch
    This command merges the changes from the source branch into the target branch but does not create a merge commit. Instead, it prepares all the changes as staged but not committed.
  3. Review the changes and make any necessary modifications or cleanups.
  4. Stage all the changes for the final commit:
    git add .
  5. Commit the changes with a descriptive message:
    git commit -m "Merge source_branch into target_branch"
    This commit will contain all the changes from the source branch as a single commit on the target branch.
  6. Push the merged commit to the remote repository:
    git push origin target_branch
    By following these steps, you can merge the changes from a source branch into a target branch as a single commit, providing a cleaner commit history.

标签:git,remote,repository,tag,Git,branch,new
From: https://www.cnblogs.com/selinachen/p/17434428.html

相关文章

  • git常用方法
    1、第一次初始化gitinitgitadd.gitcommit-m‘firstcommit’[email protected]:帐号名/仓库名.gitgitpulloriginmastergitpushoriginmaster#-f强推[email protected]:git帐号名/仓库名.git2、工作基本操作gitcheckoutmaster切......
  • isdigit、isnumeric、isdecimal
    字符串的isdigit方法用于判断字符串是否只包含数字,即0-9的字符print('1233'.isdigit())#Trueprint('12.33'.isdigit())#False字符串的isnumeric方法可用于判断字符串是否是数字,数字包括Unicode数字,byte数字(单字节),全角数字(双字节),罗马数字print('23'.isnumeric())......
  • 主流源代码管理工具—GitHub
    l Github是什么?首先,GitHub是一个面向开源及私有软件项目的托管平台,该平台于2008年4月10日正式上线,除了Git代码仓库托管及基本的Web管理界面以外,还提供了订阅、讨论组、文本渲染、在线文件编辑器、协作图谱(报表)、代码片段分享(Gist)等功能。目前,其注册用户已经超过350万,托......
  • github使用
     1.安装github客户端Git-2.40.1-64-bit.exe 2.创建代码存放目录,比如我在桌面创建github目录进入到github目录后,右键gitbash进入命令行模式初次上传:gitclonehttps://github.com/hxlsky/myibd2sdi.gitgitinitgitaddparse_ibd2sdi.pygitconfig--globaluser.namehxl......
  • 【转】Git 各种操作命令详细
    Git各种操作命令详细一般来说,日常使用git只要记住下图6个命令,就可以了。但是熟练使用,恐怕要记住60~100个命令。下面是常用的Git命令清单。几个专用名词的译名如下:Workspace:工作区Index/Stage:暂存区Repository:仓库区(或本地仓库)Remote:远程仓库一、新建代码库#在当前目录新......
  • git仓库分支管理规范
    一、常备分支(跟随git仓库一直存在):分支名称发布环境签入者自动构建发布说明hostfix_develop开发环境开发是日常开发人员进行联调自测时,将特性分支合并到此分支。将触发自动构建到开发环境develop需求明确纳入接下来的发布版本时,对应特性分支合并到此分支。然后发布到......
  • redhad安装git
    安装依赖 yuminstallcurl-develexpat-develgettext-devel\openssl-develzlib-devel[按y继续][按y继续]安装gityum-yinstallgit-core查看git版本git--version......
  • Git—常用指令
    示意图指令描述git-v查看版本号gitinit创建仓库,初始化gitclone仓库地址下载远程仓库gitconfiguser.name名称配置名称gitconfiguser.email邮箱配置邮箱gitconfig--globaluser.name名称全局配置名称gitconfig--globaluser.email名称全局配置邮箱gitstatus查看状态......
  • Gitlab安装与Gitlab-Runner注册
    1、gitlab的三种安装方式: rmp方式:wgethttps://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-12.9.0-ce.0.el7.x86_64.rpmrpm-ivhgitlab-ce-12.9.0-ce.0.el7.x86_64.rpmvim/etc/gitlab.rb#编辑站点地址gitlab-ctlreconfigure#配......
  • docker 方式部署的gitlab 升级
    升级背景:docker部署的gitlab版本11.1.4,需升级至16.0.1思路:为了不影响目前正在使用的gitlab。1.将备份拷贝至另外服务器上,升级至最高版本后,另行还原2.直接将挂载目录中的文件拷贝至另外服务器上,升级至最高版本,另行还原--经测试,失败,不推荐使用此方法2种方式将都进行实验。以......