github(二)----------日常生活简单使用git提交打码~~

来源:互联网 发布:网络打call是什么意思 编辑:程序博客网 时间:2024/06/08 03:31

日常生活使用git提交打码

上一篇已经记录了怎样结合git和github相互使用,这里要记录的是日常开发怎样去管理自己的版本库。

  1. 我们本地的代码库已经从远程克隆下来了,然后我们有新的一期需要需要开发,首先切换到develop分支,把同事的提交的代码pull下来
$ git checkout developSwitched to branch 'develop'Your branch is up-to-date with 'origin/develop'.

我这里提示我本地的已经是最新的,如果本地不是最新的

$ git pullAlready up-to-date.
  1. 然后在develop的分支里,创建自己的开发的分支
$ git checkout -b devSwitched to a new branch 'dev'$ git branch* dev  develop  master

这里我们的开发分支就创建成功了,这里建议名字取的见名知意哈,然后我们可以在这个分支进行开发

。。。。

  1. 这里介绍简单开发流程,假设现在你已经开发完了且经过自测,并且中途没有需要拉取他人代码,那么我们现在可以提交我们的分支了,首先,我们查看我们这个分支的改动的部分
$ git statusOn branch devChanges not staged for commit:  (use "git add <file>..." to update what will be committed)  (use "git checkout -- <file>..." to discard changes in working directory)        modified:   .gitignoreUntracked files:  (use "git add <file>..." to include in what will be committed)        common/        dao/        model/        one/        pom.xml        resources/        service/        src/        timer/        utils/

认真比较,是否需要提交这些代码,这里我们先要提交代码到自己本地,首先加入本地缓存区

$ git add .warning: LF will be replaced by CRLF in .gitignore.The file will have its original line endings in your working directory.warning: LF will be replaced by CRLF in common/pom.xml.The file will have its original line endings in your working directory.warning: LF will be replaced by CRLF in dao/pom.xml.

然后在提交到自己本地的代码库

$ git commit -m "maven modules"[dev 296e80c] maven modules 31 files changed, 934 insertions(+), 8 deletions(-) create mode 100644 common/pom.xml create mode 100644 common/src/main/java/org/common/App.java create mode 100644 common/src/test/java/org/common/AppTest.java create mode 100644 dao/pom.xml
  1. 这是时候我们需要把我们的分支合并到本地的develop分支上,先切换到本地的develop
$ git checkout developSwitched to branch 'develop'Your branch is up-to-date with 'origin/develop'.

这里我的本地的develop依旧是最新的(因为只有我提交代码,哈哈),这里还是更新本地的develop,从远程拉取代码

$ git pullAlready up-to-date.

现在合并dev分支和本地的develop分支

$ git merge  --no-ff -m "merge with no-ff" dev

这里需要注意的是 –no-ff 这个参数
合并分支时,如果可能,Git会用Fast forward模式,但这种模式下,删除分支后,会丢掉分支信息。

如果要强制禁用Fast forward模式,Git就会在merge时生成一个新的commit,这样,从分支历史上就可以看出分支信息。

说白点,就是如果不带上这个参数,那么我们本地开发dev分支的提交信息就会丢失,那么push到远程的develop分支的时候就会变成一条线,而不是切出来的线再合并回去的形式

image

  1. 现在我们可以查看下提交日志
$ git logcommit 5dd86856aa244f36e8e20eb4ad592c478c1a3dc3Merge: 296e80c bdf06a4Author: tangtang <whnlxxbcd@163.com>Date:   Thu Nov 10 10:44:58 2016 +0800    merge with no-ffcommit bdf06a4c0ea53ea601a7e93ff336d591d329aae1Author: tangtang <whnlxxbcd@163.com>Date:   Thu Nov 10 10:43:50 2016 +0800    delete src

查看提交记录分支图,可以带上参数

$ git log --graph --pretty=oneline --abbrev-commit*   5dd8685 merge with no-ff|\| * bdf06a4 delete src|/* 296e80c maven modules

如果分支线没有乱,那么就可以直接提交到远程develop分支了

$ git push

我们可以上github上确认一遍,我们的提交是否成功~~~~

6.最后可以删除本地分支啦,建议本地保存近期开发的三到五个分支,可以在分支命名的时候带上时间

$ git branch -d devDeleted branch dev (was 296e80c).
0 0
原创粉丝点击