美文网首页
Git 提交项目代码

Git 提交项目代码

作者: 故作谦卑 | 来源:发表于2018-07-07 00:00 被阅读0次

    Git 提交代码

    进入项目文件夹,右键打开git bash。

    //查看状态
    git status
    

    结果如下:

    On branch v1.0.0-xia
    Your branch is up to date with 'origin/v1.0.0-xia'.
    
    Changes 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:   application-dev.properties
            modified:   src/main/java/intel/common/Constants.java
            modified:   src/main/java/intel/common/GlobalConsts.java
            modified:   src/main/java/inteldao/BlackDao.java
            modified:   src/main/java/intel/kafka/service/ServiceItf.java
            modified:   src/main/java/intel/kafka/service/impl/ServiceImpl.java
            modified:   src/main/java/intel/kafka/thread/Listener.java
            modified:   src/main/resources/application.properties
    
    Untracked files:
      (use "git add <file>..." to include in what will be committed)
    
            .settings/org.eclipse.core.resources.prefs
            logs/app-06-29-2018.log.gz
            logs/intel_.log
            logs/record.log
            logs/searchRecord.log
            src/main/java/intel/dao/RecieveInfoDao.java
            src/main/java/intel/kafka/thread/ProcessMessage.java
            src/main/java/intel/vo/RecieveInfo.java
            target/
    
    no changes added to commit (use "git add" and/or "git commit -a")
    
    

    注意看Untracked files 里面的,除了那三个Java文件,其他都是没用的日志文件和目标文件,不需要提交,
    先将src/main/java/文件夹下所有文件添加,
    git add src/main/java/
    再次git status查看状态,结果如下:

    On branch v1.0.0-xia
    Your branch is up to date with 'origin/v1.0.0-xia'.
    
    Changes to be committed:
      (use "git reset HEAD <file>..." to unstage)
    
            modified:   src/main/java/intel/common/Constants.java
            modified:   src/main/java/intel/common/GlobalConsts.java
            modified:   src/main/java/inteldao/BlackDao.java
            modified:   src/main/java/intel/kafka/service/ServiceItf.java
            modified:   src/main/java/intel/kafka/service/impl/ServiceImpl.java
            modified:   src/main/java/intel/kafka/thread/Listener.java
            new file:   src/main/java/intel/dao/RecieveInfoDao.java
            new file:   src/main/java/intel/kafka/thread/ProcessMessage.java
            new file:   src/main/java/intel/vo/RecieveInfo.java
    
    Changes 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:   application-dev.properties
            modified:   src/main/resources/application.properties
    
    Untracked files:
      (use "git add <file>..." to include in what will be committed)
    
            .settings/org.eclipse.core.resources.prefs
            logs/app-06-29-2018.log.gz
            logs/intel_.log
            logs/interfaceRecord.log
            logs/searchRecord.log
            target/
    

    此时还有两个文件application-dev.properties 和 src/main/resources/application.properties
    未添加到staged状态,可以看到这两个文件是 modified状态,
    再使用git add -u 添加,(git add -u:将文件的修改、文件的删除,添加到暂存区。)
    此时,查看状态,结果如下:

    On branch v1.0.0-xia
    Your branch is up to date with 'origin/v1.0.0-xia'.
    
    Changes to be committed:
      (use "git reset HEAD <file>..." to unstage)
    
            modified:   src/main/java/intel/common/Constants.java
            modified:   src/main/java/intel/common/GlobalConsts.java
            modified:   src/main/java/inteldao/BlackDao.java
            modified:   src/main/java/intel/kafka/service/ServiceItf.java
            modified:   src/main/java/intel/kafka/service/impl/ServiceImpl.java
            modified:   src/main/java/intel/kafka/thread/Listener.java
            new file:   src/main/java/intel/dao/RecieveInfoDao.java
            new file:   src/main/java/intel/kafka/thread/ProcessMessage.java
            new file:   src/main/java/intel/vo/RecieveInfo.java
            modified:   application-dev.properties
            modified:   src/main/resources/application.properties
    
    Untracked files:
      (use "git add <file>..." to include in what will be committed)
    
            .settings/org.eclipse.core.resources.prefs
            logs/app-06-29-2018.log.gz
            logs/intellif_.log
            logs/interfaceRecord.log
            logs/searchRecord.log
            target/
    

    检查需要的文件是否都处于stage状态,使用git commit -m "注释"进行提交,
    查看状态,

    [v1.0.0-xia e435504] 注释
     11 files changed, 232 insertions(+), 13 deletions(-)
     create mode 100644 src/main/java/intellif/dao/KafkaRecieveInfoDao.java
     create mode 100644 src/main/java/intellif/kafka/thread/ProcessKafkaMessage.java
     create mode 100644 src/main/java/intellif/vo/KafkaRecieveInfo.java
    

    此时,先不要急着git pull,先拉取最新代码,使用git pull -origin v1.0.0-xia,

    关于git pull

    git pull命令的作用是,取回远程主机某个分支的更新,再与本地的指定分支合并。它的完整格式稍稍有点复杂。
    
    $ git pull <远程主机名> <远程分支名>:<本地分支名>
    比如,取回origin主机的next分支,与本地的master分支合并,需要写成下面这样。
    
    $ git pull origin next:master
    如果远程分支是与当前分支合并,则冒号后面的部分可以省略。
    
    $ git pull origin next
    

    拉取代码可以看到结果:

    remote: Counting objects: 51, done.
    remote: Compressing objects: 100% (40/40), done.
    remote: Total 51 (delta 8), reused 30 (delta 6)
    Unpacking objects: 100% (51/51), done.
    From http://192.168.90.8/platform/BaseFramework
     * branch            v1.0.0-xia -> FETCH_HEAD
       fc8c365..23550cb  v1.0.0-xia -> origin/v1.0.0-xia
    Auto-merging src/main/java/intel/service/impl/ServiceImpl.java
    Auto-merging application-dev.properties
    CONFLICT (content): Merge conflict in application-dev.properties
    Automatic merge failed; fix conflicts and then commit the result.
    

    注意提示:CONFLICT (content): Merge conflict in application-dev.properties
    表示文件有冲突,打开文件进行修改,删掉git生成的代码就可以了。
    修改完后,再次git add -u,添加修改文件到stage状态,
    之后git commit -m "注释"进行提交,
    最后就可以git push -origin v1.0.0-xia 上传代码。建议带上-origin v1.0.0-xia参数。
    对于文件状态,可以参考下图:

    git_状态

    相关文章

      网友评论

          本文标题:Git 提交项目代码

          本文链接:https://www.haomeiwen.com/subject/ngjiuftx.html