用着 Mac Androidstudio开发Android,好多知识 会比用window系统开发的要少,最近遇到一个问题:
若命令未生效或报错 请参考( git学习笔记)
使用 git 进行版本管理时,改动的文档并没有被我所使用的版本管理工具(我用的SourceTree)所捕获到,而且在studio上面进行提交的时候,也没有找到git的选项,为此找了好半天。可能是我刚开始理解错了:用git命令进行操作文件,无论用什么版本工具,都会与之同步;也就是说所有git版本管理工具若出现对文件失控,都可以用git 命令进行调整。
先排查,根目录中的.git文件是否还存在,这是一个隐藏文件,若你的隐藏文件不可见,那么先让你的电脑展示隐藏文件。如果没有 则执行下面代码,让这个目录受git管理(命令输入之后,按下回车键 即可执行)
git init
像我上面遇到的问题,studio与git失去联系,需要重新提交一边项目,但是因为怕忽略文件失效,所以提交之前,需要先把之前托管的文件清理一下(一定要保证项目在本地有最新版本)
git rm -r --cached .
上面的命令后面的‘.’代表的是当前目录,也可以替换成 /**/**格式的路径,不过以防万一,我们最好进入到项目根目录进行操作
然后进入到根目录下把项目添加进去,执行
git commit -m 'ignore something'
先把忽略文件提交上去,然后添加项目
git add -f .
注意这行代码的意义,它的作用是把代码更新信息提交到仓库,但是代码并没有改动,需要 执行
git commit -m .
到这一步,基本算是弄好了这个问题 ,无非就是清理服务器的代码,提交忽略文件,在重新提交代码,
当然,如果服务器代码是最新的,也可以重新从服务器clone一个项目到本地,
可以把本地的代码文件全部删除(重要配置文件记得留下),或者换个位置重新下载代码,然后开始执行
git init
让文件夹变成Git 可管理的仓库,,
然后再把代码克隆下来
git clone "你的仓库地址"
欧了,项目到此为止,想看更多关于 git 命令 ,可以输入命令
git help
以下为输出的详情,第一行跟我们说明了命令如何使用, 下面每一个命令后面都跟着具体的意思。
usage: git [--version] [--help] [-C <path>] [-c <name>=<value>]
[--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
[-p | --paginate | -P | --no-pager] [--no-replace-objects] [--bare]
[--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
<command> [<args>]
These are common Git commands used in various situations:
start a working area (see also: git help tutorial)
clone Clone a repository into a new directory
init Create an empty Git repository or reinitialize an existing one
work on the current change (see also: git help everyday)
add Add file contents to the index
mv Move or rename a file, a directory, or a symlink
reset Reset current HEAD to the specified state
rm Remove files from the working tree and from the index
examine the history and state (see also: git help revisions)
bisect Use binary search to find the commit that introduced a bug
grep Print lines matching a pattern
log Show commit logs
show Show various types of objects
status Show the working tree status
grow, mark and tweak your common history
branch List, create, or delete branches
checkout Switch branches or restore working tree files
commit Record changes to the repository
diff Show changes between commits, commit and working tree, etc
merge Join two or more development histories together
rebase Reapply commits on top of another base tip
tag Create, list, delete or verify a tag object signed with GPG
collaborate (see also: git help workflows)
fetch Download objects and refs from another repository
pull Fetch from and integrate with another repository or a local branch
push Update remote refs along with associated objects
'git help -a' and 'git help -g' list available subcommands and some
concept guides. See 'git help <command>' or 'git help <concept>'
to read about a specific subcommand or concept.