Android APK开发基础——git代码管理
Git代码管理工具
https://blog.****.net/free_wind22/article/details/50967723
git下载安装
1、Git下载安装 , Windows用户下载地址:https://git-for-windows.github.io/ ,然后按默认选项安装即可。
2、安装完成后,在开始菜单里找到“Git”->“Git Bash”,蹦出一个类似命令行窗口的东西,就说明Git安装成功 。
需要填写用户名和邮箱作为一个标识
[email protected] MINGW64 ~
$ git config --global user.name "huangyuan"
[email protected] MINGW64 ~
$ git config --global user.email "[email protected]"
本地仓库
1、在本地新建了文件夹作为本地仓库,把文件添加到版本库中
首次创建提交:
$ git init
$ git add E_001F_app1
$ git commit -m "e001f first commit"
$ git status
$ git log
$ git remote add origin https://github.com/yuanhhyuan/E001f.git
$ git push -u origin master
后续更新提交:
$ git status
modified: NewZxing/app/src/main/res/layout/activity_main.xml
$ git add NewZxing/app/src/main/res/layout/activity_main.xml
$ git commit -m "2nd comit"
$ git push origin master
修改多个文件后一次性提交:
$ git status
modified: ScanZxing/.idea/inspectionProfiles/Project_Default.xml
deleted: ScanZxing/app/src/androidTest/java/com/zxcgw/wifi/wifiautoconnect/ExampleInstrumentedTest.java
modified: ScanZxing/app/src/main/AndroidManifest.xml
deleted: ScanZxing/app/src/main/java/com/zxcgw/wifi/wifiautoconnect/wifi/WifiAdmin.java
deleted: ScanZxing/app/src/main/java/com/zxcgw/wifi/wifiautoconnect/wifi/WifiLinstener.java
$ git add -A
$ git commit -a -m "2nd commit"
$ git push origin master
示例:
[email protected] MINGW64 ~
$ cd f:
[email protected] MINGW64 /f
$ cd git
[email protected] MINGW64 /f/git
$ cd e001f1
[email protected] MINGW64 /f/git/e001f1
$ git init
Initialized empty Git repository in F:/git/e001f1/.git/
然后把andstudio代码目录E_001F_app1拷贝到/f/git/e001f1,目录如下:
[email protected] MINGW64 /f/git/e001f1 (master)
$ git add E_001F_app1
warning: LF will be replaced by CRLF in E_001F_app1/app/.idea/gradle.xml.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in E_001F_app1/app/.idea/misc.xml.
The file will have its original line endings in your working directory.
……
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in E_001F_app1/gradlew.
The file will have its original line endings in your working directory.
[email protected] MINGW64 /f/git/e001f1 (master)
$ git commit -m "e001f first commit"
[master (root-commit) 1fac60f] e001f first commit
142 files changed, 9268 insertions(+)
create mode 100644 E_001F_app1/.gitignore
……
create mode 100644 E_001F_app1/settings.gradle
[email protected] MINGW64 /f/git/e001f1 (master)
$ git status
On branch master
nothing to commit, working tree clean
[email protected] MINGW64 /f/git/e001f1 (master)
$ git diff E_001F_app1/app/src/main/java/com/zxcg/app/activity/MainActivity.java
diff --git a/E_001F_app1/app/src/main/java/com/zxcg/app/activity/MainActivity.ja va b/E_001F_app1/app/src/main/java/com/zxcg/app/activity/MainActivity.java
index c40de99..9fc127b 100644
--- a/E_001F_app1/app/src/main/java/com/zxcg/app/activity/MainActivity.java
+++ b/E_001F_app1/app/src/main/java/com/zxcg/app/activity/MainActivity.java
@@ -28,6 +28,8 @@ public class MainActivity extends BaseActivity implements IBod yTempCallback {
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
initSerialPort();
+
+ //git测试测试测试测试
}
[email protected] MINGW64 /f/git/e001f1 (master)
$ git log
commit 1fac60f2c04fb15cf6658a52c7ca4bbbd2c42684 (HEAD -> master)
Author: huangyuan <[email protected]>
Date: Tue May 22 11:08:08 2018 +0800
e001f first commit
[email protected] MINGW64 /f/git/e001f1 (master)
$ git add E_001F_app1/app/src/main/java/com/zxcg/app/activity/MainActivity.java
[email protected] MINGW64 /f/git/e001f1 (master)
$ git commit -m "mainactivity add git测试" [master 01f97bb] mainactivity add git测试
1 file changed, 2 insertions(+)
[email protected] MINGW64 /f/git/e001f1 (master)
$ git status
On branch master
nothing to commit, working tree clean
[email protected] MINGW64 /f/git/e001f1 (master)
$ git log
commit 01f97bbdb4f8a311f59a48d53259329f097baca4 (HEAD -> master)
Author: huangyuan <[email protected]>
Date: Tue May 22 11:29:03 2018 +0800
mainactivity add git测试
commit 1fac60f2c04fb15cf6658a52c7ca4bbbd2c42684
Author: huangyuan <[email protected]>
Date: Tue May 22 11:08:08 2018 +0800
e001f first commit
[email protected] MINGW64 /f/git/e001f1 (master)
$ git reset --hard HEAD^
HEAD is now at 1fac60f e001f first commit
=====
理解工作区与暂存区的区别?
工作区:就是你在电脑上看到的目录,比如目录下testgit里的文件(.git隐藏目录版本库除外)。或者以后需要再新建的目录文件等等都属于工作区范畴。
版本库(Repository):工作区有一个隐藏目录.git,这个不属于工作区,这是版本库。其中版本库里面存了很多东西,其中最重要的就是stage(暂存区),还有Git为我们自动创建了第一个分支master,以及指向master的一个指针HEAD。
我们前面说过使用Git提交文件到版本库有两步:
第一步:是使用 git add 把文件添加进去,实际上就是把文件添加到暂存区。
第二步:使用git commit提交更改,实际上就是把暂存区的所有内容提交到当前分支上。
========
远程仓库
[email protected] MINGW64 /f/git/e001f1 (master)
$ git remote add origin https://github.com/yuanhhyuan/E001f.git
[email protected] MINGW64 /f/git/e001f1 (master)
$ git push -u origin master
Counting objects: 204, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (179/179), done.
Writing objects: 100% (204/204), 4.65 MiB | 313.00 KiB/s, done.
Total 204 (delta 28), reused 0 (delta 0)
remote: Resolving deltas: 100% (28/28), done.
To https://github.com/yuanhhyuan/E001f.git
* [new branch] master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.