由于我使用的是Mac,所以仅仅针对今天学习的Mac上的创建git本地仓库经验来分享一下。
贴个链接,git入门好帮手 http://rogerdudler.github.io/git-guide/index.zh.html
首先是安装:由于我的电脑之前装过了,所以没有尝试再去装一遍哦,不过不难下载对应的OS的版本即可,上面链接也有说明。
接下来我们就开始新建我们的本地仓库了:
1.首先在 iTerm 里面使用命令行将目录切到你的某个Android Studio的工程文件下
cd file
2.在该目录下执行 git init 初始化本地仓库
3.在提交代码相关文件之前,我们要去配置.gitignore文件,这里给大家介绍一个网站自动生成.gitignore的相关信息。
Android Studio的工程的话,大概要选择这几个关键词,点击Generate即可生成,如下所示:
# Created by https://www.gitignore.io/api/android,intellij,eclipse,gradle
### Android ###
# Built application files
*.apk
*.ap_
# Files for the ART/Dalvik VM
*.dex
# Java class files
*.class
# Generated files
bin/
gen/
out/
# Gradle files
.gradle/
build/
# Local configuration file (sdk path, etc)
local.properties
# Proguard folder generated by Eclipse
proguard/
# Log Files
*.log
# Android Studio Navigation editor temp files
.navigation/
# Android Studio captures folder
captures/
# Intellij
*.iml
.idea/workspace.xml
# Keystore files
*.jks
### Android Patch ###
gen-external-apklibs
### Intellij ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff:
.idea/workspace.xml
.idea/tasks.xml
.idea/dictionaries
.idea/vcs.xml
.idea/jsLibraryMappings.xml
# Sensitive or high-churn files:
.idea/dataSources.ids
.idea/dataSources.xml
.idea/dataSources.local.xml
.idea/sqlDataSources.xml
.idea/dynamic.xml
.idea/uiDesigner.xml
# Gradle:
.idea/gradle.xml
.idea/libraries
# Mongo Explorer plugin:
.idea/mongoSettings.xml
## File-based project format:
*.iws
## Plugin-specific files:
# IntelliJ
/out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
### Intellij Patch ###
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
# *.iml
# modules.xml
### Eclipse ###
.metadata
bin/
tmp/
*.tmp
*.bak
*.swp
*~.nib
local.properties
.settings/
.loadpath
.recommenders
# Eclipse Core
.project
# External tool builders
.externalToolBuilders/
# Locally stored "Eclipse launch configurations"
*.launch
# PyDev specific (Python IDE for Eclipse)
*.pydevproject
# CDT-specific (C/C++ Development Tooling)
.cproject
# JDT-specific (Eclipse Java Development Tools)
.classpath
# Java annotation processor (APT)
.factorypath
# PDT-specific (PHP Development Tools)
.buildpath
# sbteclipse plugin
.target
# Tern plugin
.tern-project
# TeXlipse plugin
.texlipse
# STS (Spring Tool Suite)
.springBeans
# Code Recommenders
.recommenders/
### Gradle ###
.gradle
build/
# Ignore Gradle GUI config
gradle-app.setting
# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
!gradle-wrapper.jar
# Cache of project
.gradletasknamecache
# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898
# gradle/wrapper/gradle-wrapper.properties
将其复制出来之后在如下图的目录下,找到改文件
一定要在gradle这个目录下的改文件才是针对全部文件的,在app目录下也有一个.gitignore文件,但是他的作用范围只在app文件夹下,所以要切记在gradle目录下的文件上去修改。
4.我们将修改的.gitignore文件上传到我们的本地仓库,首先执行 git add .gitignore 命令,将其暂存,然后执行 git commit .gitignore -m "这里填写你想要填写的注释即可",这样就在本地仓库里提交了改文件。
PS:可能有人会问,为什么要配置这个.gitignore文件,为什么要先去提交这个文件呢?
.gitignore顾名思义就是忽视某些文件的意思,有一些是可以在编译的时候自动生成,我们没有必要去让这些文件浪费空间,所以才会需要配置.gitignore文件,只有先将其提交上去,我们之后提交代码才会发挥这个ignore的作用哦~~~
5.接下来我们来进行第一次代码文件提交 我一般都是先用 git add . 将全部文件一起暂存,然后一起执行 git commit . -m "注释",这样我们的本地仓库就建好啦~
END