安卓Git的使用git

你应该掌握的Git常用操作

2016-09-02  本文已影响1722人  daking

获取与创建项目

git init

git clone

添加与提交

基本流程

  1. 使用git add添加需要追踪的新文件和待提交的更改;
  2. 使用git statusgit diff查看有何改动;
  3. 使用git commit提交快照。

git add


git commit

git status

git diff



git show

删除与恢复

git rm



恢复



版本控制

版本号

git log


git reflog

git tag




远程项目

git remote




git push

拉取

分支

git branch



git checkout

git merge

合并冲突

子模块

添加子模块

clone一个带子模块的Git仓库

  1. 方案1
    1. git clone Git仓库路径
    2. 初始化以及更新子模块:git submodule initgit submodule update
  2. 方案2
    git clone --recursive Git仓库路径 参数--recursive会递归初始化并更新每个子模块。

更新子模块

  1. 先更新子模块,git submodule update。若嵌套多层子模块,则git submodule foreach "git submodule update"
  2. 再更新主仓库。

子模块的修改提交

  1. 在子模块的根目录下,切换到要修改的分支,再进行代码修改。这是因为submodule的HEAD默认是处于游离状态,它并没在任何分支上。
  2. 在子模块的根目录进行Git提交。
  3. 在主Git仓库的根目录进行Git提交。

删除子模块

  1. 删除子模块的Git缓存,git rm --cached android-client-common/

  2. 删除子模块的本地文件,rm -rf android-client-common/

  3. 删除与此子模块相关的配置

    rm -rf .git/modules/android-client-common/ 
    .gitmodules中的相关配置 
    .git/config中的相关配置
    
  4. 修改提交

    git add .gitmodules 
    git commit -m 'remove submodule: android-client-common' 
    git push 
    

git config



我的博客

上一篇 下一篇

猜你喜欢

热点阅读