不能讲我以前没有使用过git和github但是没有熟悉,所以现在也是从头开始来。
好吧,(既然推荐了,再看了下次觉得需要再次编辑)
1.多看文档,github本身的帮助文档本身已经挺不错的了。呵呵。
创建一个仓库,这个过程我是比较熟悉了。
2.clone到本地。我还是选择使用https吧。这个感觉方便点。如果使用ssh的话,需要rsa之类的。
3.修改文件及提交修改:
4.配置本地用户登录记住密码
具体操作:
1.(假设已经在github上面创建好了仓库)
使用git clone命令将线上仓库克隆下来:
banxi1988@banxi:~/work/android$ ls
DeskClock SlideAndGesture.apk xiyili
banxi1988@banxi:~/work/android$ git clone https://github.com/banxi1988/weibo.git
Cloning into 'weibo'...
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
banxi1988@banxi:~/work/android$ ls
DeskClock SlideAndGesture.apk weibo xiyili
banxi1988@banxi:~/work/android$ cd weibo/
(当然,也可以使用类似如下的命令指定目录
$git clone https://github.com/banxi1988/weibo.git myweibo
2.接下来就是要测试修改提交
要在git中完成一次提交,一般需要经过,修改或者添加,暂存,提交,推送(push)
(2.1)修改(这谁都会)
banxi1988@banxi:~/work/android/weibo$ ls
README.md
banxi1988@banxi:~/work/android/weibo$ vi README.md
(2.2)查看当前状态,如果你使用过svn的话肯定会记得这个命令$svn status
很高兴git也有这个命令,$git status,更开心的是git status输入的信息更多,更人性化。体验也就更好了。
banxi1988@banxi:~/work/android/weibo$ git status
# On branch master
# 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: README.md
#
no changes added to commit (use "git add" and/or "git commit -a")
banxi1988@banxi:~/work/android/weibo$ git help commit
从上面的输出看来git是不是更好呢?
我还是将上面的翻译一下吧。:
banxi1988@banxi:~/work/android/weibo$ git status
# 在master分支
# 用于提交还没有暂存的修改::
# 使用"git add <file>..."来更新哪些需要提交
# 使用"git checkout --<file>..." 来撤消在工作目录中的修改
#
# 已修改: README.md
#
没有添加到提交的修改 (使用 "git add" 和/或 "git commit -a")
banxi1988@banxi:~/work/android/weibo$ git help commit
如果对于commit或者add不了解,别忘了使用git的帮助哦。我是习惯使用帮助来学习的。呵呵。
$git help commit
$git help add
(2.3)暂存
使用$git add来暂存文件的修改,在添加文件时,$git add命令也起到一个将文件添加的版本控制中的作用。
使用命令之后,使用git status查看下,区别是上面的是modifed这个单词也变成了绿色。
banxi1988@banxi:~/work/android/weibo$ git add README.md
banxi1988@banxi:~/work/android/weibo$ git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: README.md
#
banxi1988@banxi:~/work/android/weibo$
(2.4)提交
使用$git commit 命令
banxi1988@banxi:~/work/android/weibo$ git commit README.md -m"add a line"
[master f4776c7] add a line
1 file changed, 2 insertions(+)
banxi1988@banxi:~/work/android/weibo$
如果你使用过svn那么会,很显然的发现-m选项后面跟的是提交的注释。
(2.5)暂存提交两步并做一步。
只要在使用$git commit时加一个-a选项即可。
(2.6)推送提交到远程仓库,使用git push
下面命令中的$git push orign master
指的是将本地master分支提交的修改推送的修改提交到名为orign的远程仓库中去。
banxi1988@banxi:~/work/android/weibo$ git push origin master
Username for 'https://github.com': banxi1988@gmail.com
Password for 'https://banxi1988@gmail.com@github.com':
fatal: Authentication failed
banxi1988@banxi:~/work/android/weibo$ git push origin master
Username for 'https://github.com': banxi1988
Password for 'https://banxi1988@github.com':
Everything up-to-date
banxi1988@banxi:~/work/android/weibo$ git --help
usage: git [--version] [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
[-p|--paginate|--no-pager] [--no-replace-objects] [--bare]
[--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
[-c name=value] [--help]
<command> [<args>]
The most commonly used git commands are:
add Add file contents to the index
bisect Find by binary search the change that introduced a bug
branch List, create, or delete branches
checkout Checkout a branch or paths to the working tree
clone Clone a repository into a new directory
commit Record changes to the repository
diff Show changes between commits, commit and working tree, etc
fetch Download objects and refs from another repository
grep Print lines matching a pattern
init Create an empty git repository or reinitialize an existing one
log Show commit logs
merge Join two or more development histories together
mv Move or rename a file, a directory, or a symlink
pull Fetch from and merge with another repository or a local branch
push Update remote refs along with associated objects
rebase Forward-port local commits to the updated upstream head
reset Reset current HEAD to the specified state
rm Remove files from the working tree and from the index
show Show various types of objects
status Show the working tree status
tag Create, list, delete or verify a tag object signed with GPG
See 'git help <command>' for more information on a specific command.
banxi1988@banxi:~/work/android/weibo$ git commit -a -m "modife readme add author info"
[master 909a435] modife readme add author info
Committer: banxi1988 <banxi1988@banxi.(none)>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:
git config --global user.name "Your Name"
git config --global user.email you@example.com
After doing this, you may fix the identity used for this commit with:
git commit --amend --reset-author
1 file changed, 5 insertions(+), 1 deletion(-)
banxi1988@banxi:~/work/android/weibo$ git push origin master
Username for 'https://github.com': banxi1988
Password for 'https://banxi1988@github.com':
To https://github.com/banxi1988/weibo.git
01ff376..909a435 master -> master
banxi1988@banxi:~/work/android/weibo$ git config --global user.name "banxi1988"
banxi1988@banxi:~/work/android/weibo$ git config --global user.email "banxi1988@gmail.com"
banxi1988@banxi:~/work/android/weibo$ git config --global credential.helper cache
banxi1988@banxi:~/work/android/weibo$ git config --global credential.helper 'cache --timeout=7200000'
banxi1988@banxi:~/work/android/weibo$
然后 创建Android项目:
banxi1988@banxi:~/work/android/weibo$ android create project --target 6 --name gweibo --path . --activity HomeActivity --package me.banxi.app
Error: Project folder '.' is not empty. Please consider using 'android update' instead.
Created directory /home/banxi1988/work/android/weibo/src/me/banxi/app
Added file ./src/me/banxi/app/HomeActivity.java
Created directory /home/banxi1988/work/android/weibo/res
Created directory /home/banxi1988/work/android/weibo/bin
Created directory /home/banxi1988/work/android/weibo/libs
Created directory /home/banxi1988/work/android/weibo/res/values
Added file ./res/values/strings.xml
Created directory /home/banxi1988/work/android/weibo/res/layout
Added file ./res/layout/main.xml
Created directory /home/banxi1988/work/android/weibo/res/drawable-xhdpi
Created directory /home/banxi1988/work/android/weibo/res/drawable-hdpi
Created directory /home/banxi1988/work/android/weibo/res/drawable-mdpi
Created directory /home/banxi1988/work/android/weibo/res/drawable-ldpi
Added file ./AndroidManifest.xml
Added file ./build.xml
Added file ./proguard-project.txt
banxi1988@banxi:~/work/android/weibo$ ls
AndroidManifest.xml build.xml proguard-project.txt res
ant.properties libs project.properties src
bin local.properties README.md
banxi1988@banxi:~/work/android/weibo$
之前可以使用android list targets来查看可用的targets及其ID。
设置gitingore
banxi1988@banxi:~/work/android/weibo$ vi .gitignore
banxi1988@banxi:~/work/android/weibo$ ls
AndroidManifest.xml build.xml local.properties README.md
ant.properties gen proguard-project.txt res
bin libs project.properties src
banxi1988@banxi:~/work/android/weibo$ git add .
banxi1988@banxi:~/work/android/weibo$ git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# new file: .gitignore
# new file: AndroidManifest.xml
# new file: ant.properties
# new file: build.xml
# new file: gen/R.java.d
# new file: gen/me/banxi/app/BuildConfig.java
# new file: gen/me/banxi/app/R.java
# new file: local.properties
# new file: proguard-project.txt
# new file: project.properties
# new file: res/drawable-hdpi/ic_launcher.png
# new file: res/drawable-ldpi/ic_launcher.png
# new file: res/drawable-mdpi/ic_launcher.png
# new file: res/drawable-xhdpi/ic_launcher.png
# new file: res/layout/main.xml
# new file: res/values/strings.xml
# new file: src/me/banxi/app/HomeActivity.java
#
banxi1988@banxi:~/work/android/weibo$
我在weibo目录下新创建的.gitignore文件中内容是
bin/*
可以看到 上面确实没有将bin/目录中的东西添加进来。
另外之前还按照
https://help.github.com/articles/ignoring-files
配置的全局的ignore选项。。
然后提交到本地。然后推送到github服务器中:
banxi1988@banxi:~/work/android/weibo$ git commit -a -m "init android project "
[master d8db634] init android project
17 files changed, 238 insertions(+)
create mode 100644 .gitignore
create mode 100644 AndroidManifest.xml
create mode 100644 ant.properties
create mode 100644 build.xml
create mode 100644 gen/R.java.d
create mode 100644 gen/me/banxi/app/BuildConfig.java
create mode 100644 gen/me/banxi/app/R.java
create mode 100644 local.properties
create mode 100644 proguard-project.txt
create mode 100644 project.properties
create mode 100644 res/drawable-hdpi/ic_launcher.png
create mode 100644 res/drawable-ldpi/ic_launcher.png
create mode 100644 res/drawable-mdpi/ic_launcher.png
create mode 100644 res/drawable-xhdpi/ic_launcher.png
create mode 100644 res/layout/main.xml
create mode 100644 res/values/strings.xml
create mode 100644 src/me/banxi/app/HomeActivity.java
banxi1988@banxi:~/work/android/weibo$ git push origin master
To https://github.com/banxi1988/weibo.git
0a022b5..d8db634 master -> master
banxi1988@banxi:~/work/android/weibo$