想搞个Spring源码看看,结果被Git与Gradle玩得死去活来。一怒之下,决定先集中火力各个击破。
官网教程一:安装Git
1. 下载Git wndows版(http://git-scm.com/download/win)。安装,选项默认。
2. 运行Git Bash (不是Windows command line,是在程序里面)
3. 设置用户名和邮箱。在git bash中分别键入
git config --global user.name "Your Name Here"
git config --global user.email "your_email@example.com"
并回车。
官网教程二:创建一个Repo(仓库,Repository)
1. 打开 https://github.com/new 设置一个Reposiroty name并点击Create按钮。我创建了一个叫mySpring的Repo。
2(个人). 在Eclipse里创建了一个mySpring项目。项目位于 E:\workspaces\java_study\mySpring
3. Git Bash中执行
cd E:/workspaces/java_study/mySpring
git init
git init 命令在mySpring目录下创建隐藏文件夹 .git,可以把这个文件夹视为一个本地仓库。(貌似自动创建了一个master分支)
4. 在项目根目录创建README文件,准备实验commit
5. 提交(Commit)至本地仓库
git add README
# Stages your README file, adding it to the list of files to be committed
git commit -m 'first commit'
# 提交文件,添加信息 "first commit"。
6. 推送(Push)提交内容至远程仓库
git remote add origin https://github.com/klg0705/mySpring.git
# 在GitHub上创建一个叫 "origin"的远程仓库
git push origin master
# 把 "master" 分支的内容提交到GitHub
现在在GitHub上可以看到README文件了。
官网教程三:Fork一个仓库(Fork a Repo)
1. 打开 https://github.com/octocat/Spoon-Knife,点击右上角的Fork按钮。
2. 你已经Fork了该仓库,但它还只在GitHub上,你需要将它Clone到本地
cd e:/
git clone https://github.com/klg0705/Spoon-Knife.git
# 将指定仓库复制到Git Bash当前目录
3. 克隆的仓库有一个默认的远程仓库 origin,该远程仓库指向你自己的fork,而不是原始仓库,如上所见git clone https://github.com/klg0705/Spoon-Knife.git。为了继续追踪原始仓库的变更,我们需要添加另一个远程仓库 “upstream”
cd Spoon-Knife
git remote add upstream https://github.com/octocat/Spoon-Knife.git
# 将原始仓库指定给 upstream 远程仓库
git fetch upstream
# 将文件变动都拉到(Pull)本地仓库,但不改变本地文件内容。
git merge upstream/master
# 将变动合并到本地文件
4. 创建分支(branch)
git branch testbranch
# 在我的Spoon-Knife中创建一个分支。此时GitHub上并没有该分支。
git checkout testbranch
# 将该分支设为活动(active)分支
或者使用等效的简化命令:
git checkout -b testbranch
然后我创建一个新文件newFile,并提交
touch newFile
git add newFile
git commit -m 'newFile in testbranch' 此时GitHub上依然没有该分支。
git checkout master
# 将master分支设为活动分支
git merge testbranch
# 将testbranch分支的内容合并到master分支。自动合并,因为没冲突。
git commit -m 'commit without add'
git push origin master
newFile被推送到GitHub上(??我不是没 git add newFile吗?而且GitHub文件注释为'newFile in testbranch' )
git branch -d testbranch
# 删除分支
5. 删除仓库或Fork
在GitHub上操作,见https://help.github.com/articles/deleting-a-repository