git命令使用
使用前:
windows 安装完git ,[comand+R]在cmd下面执行 git 命令时,可能会出现“git不是内部命令或外部命令”,原因是用户在安装git时没有配置相应的“路径”,专业术语叫环境变量。windows操作系统下的cmd窗口要执行一些第三方软件的命令行,就必须配置相应的路径来告知windows操作系统。如果读者安装了Chocolatey[Windows命令行软件管理包系统],可以在Chocolatey环境下使用命令行安装git,此时就不需要我们手动配置git的环境变量了。
git环境变量配置路径如下:[git版本不一样,文件路径可能会有变化]
1.找到你电脑上的git安装中bin的路径,如:E:\安装吧\Git\Git\bin;同时,找到git安装路径中git-core的位置,如:E:\安装吧\Git\Git\mingw64\libexec\git-core;
2.配置系统变量。右键“计算机”->“属性”->“高级系统设置”->“环境变量”->在下方的“系统变量”中找到“path”->选中“path”并选择“编辑”->将1中找到的bin和git-core路径复制到其中保 存并退出。(注意,系统变量path的配置中,每个路径之间以分号;分割)
此时在cmd窗口下执行:
C:\Users\wn>git --version
git version 2.10.0.windows.1
使用git --help命令来帮助你更加全面的认识git命名
C:\Users\wn>git --help
usage: git [--version] [--help] [-C <path>] [-c name=value]
[--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>]
<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.
git config user.name
git config user.email
git config --global user.name "username"
git config --global user.email "email"
首先,我们先建立一个工程,使用git clone [url] 从远程服务器[远程仓库]下载文件形成本地仓库[Repostory]或者 git init [初始化一个本地仓库,cd到该文件夹下],此时你可以参照Git 常用命令详解(二)这篇文章。
在初始化[建立]工程后,我们就剋使用相关git版本控制命令了。
:wq 保存后退出vi,若为 :wq! 则为强制储存后退出(常用)
:w 保存但不退出(常用)
:w! 若文件属性为『只读』时,强制写入该档案
:q 离开 vi (常用)
:q! 若曾修改过档案,又不想储存,使用 ! 为强制离开不储存档案。
:e! 将档案还原到最原始的状态!
2:git branch 查看当前自己所在的分支
3:git branch -a 查看服务器的所有分支以及自己当前所在的分支
表示要修改当前版本的倒数第三次状态。
这个命令出来之后,会出来三行东东:
pick:*******
pick:*******
pick:*******
如果你要修改哪个,就把那行的pick改成edit,然后退出。
这时通过git log你可以发现,git的最后一次提交已经变成你选的那个了,这时再使用:
git commit --amend
来对commit进行修改。
修改完了之后,要回来对不对?
使用git rebase --continue
OK,一切都搞定了。
9:git push <远程主机名> <本地分支名>:<远程分支名> 例如:git push origin branchName(把命名为branchName的本地分支推送到服务器)【origin:远程服务器的别名】
v一种是直接写完整的远程主机地址
git push ssh://git@dev.lemote.com/rt4ls.git master:master
一种是给远程主机一个简短的映射名然后使用映射名
git remote add origin ssh://git@dev.lemote.com/rt4ls.git
git push origin master:master
1 取回origin主机的next分支,与本地的master分支合并,需要写成下面这样。
git pull origin next:master
2 如果省略本地分支名,则表示远程分支是与当前分支合并。
git pull origin next
上面命令表示,取回origin/next分支,再与当前分支合并。
3 如果当前分支与远程分支存在追踪关系,git pull就可以省略远程分支名。
git pull origin
上面命令表示,本地的当前分支自动与对应的origin主机”追踪分支”(remote-tracking branch)进行合并。
4 如果当前分支只有一个追踪分支,连远程主机名都可以省略。
git pull
上面命令表示,当前分支自动与唯一一个追踪分支进行合并。
10:git checkout --track origin/branchName (切换为远程服务器上的命名为branchName的远程分支)
11:如果你的搭档要把他本地的分支给关联到服务器上命名为branchName的远程分支,请执行以下操作,
git branch --set-upstream localBranchName origin/branchName
(为本地分支添加一个对应的远程分支 与之相对应)->这行命令用来关联本地的分支与服务器上的分支
先建立本地的代码库:
mkdir android_source;
cd android_source;
然后初始化本地仓库:git init
这条命令下去,其实默认建立了master.但是远程仓库是develop。这里如果你不建立本地分支,等下你提交代码的时候就会发现develop是空的错误提示。
我们用git branch 看一下,是不是?
然后建立本地develop分支命令:git branch develop
好了,我们需要切换的当前分支为develop了。git checkout develop;
然后add 一下当前目录:git add .
git commit -m "local branch develop init"
然后解析来就要绑定本地仓库和远程仓库了。
git remote add origin http://www.github.teste.git
到这里,本地的分支develop 和远程仓库就有联系了,我们把远程的代码pull下来。
git pull origin develop (注意不是master)
这样远程的分支代码就弄到本地了。
如果本地你已经有代码,你pull下来的代码估计和本地有冲突,然后你需要解决冲突。
解决完冲突后,需要把这些解决好的文件add一下。
git add *
git commit -m "fix conflict"
如果这个时候你被提示说有一些文件还没有merge,那说明有的文件你还没有修改,修改好它再add,然后你提交到服务器,就没问题了。
git push -u origin develop
接着,git status -uno:可以让你看到当前分支是否领先/落后/分叉于它跟踪的远程分支
或者,git show-branch *master:可以让你看到所有名字最后是 master 的分支的 commits,因此你可以看到 origin/master 和 master 在 commits 层面上的差异
最后,git diff origin/master:可以让你看到 origin/master 和 master 在代码(文件)层面上的差异
推荐:
阮一峰------常用 Git 命令清单:http://www.ruanyifeng.com/blog/2015/12/git-cheat-sheet.html
廖雪峰-------git教程:https://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/
git官网-------https://git-scm.com/docs
远程重命名项目分支-------------------------------------http://blog.youkuaiyun.com/andypan1314/article/details/9271903
Git指南二 查看、删除、重命名远程分支-----------http://blog.youkuaiyun.com/SunnyYoona/article/details/52065544
本地Git仓库和远程仓库的创建及关联---------------http://www.jianshu.com/p/dcbb8baa6e36
Git--将服务器代码更新到本地-------------------------https://www.cnblogs.com/sunshine2016/p/5749098.html
&和|是前后的命令都会执行
显示隐藏文件:
1:defaults write com.apple.Finder AppleShowAllFiles YES
2:KillAll Finder
不显示隐藏文件:
1:defaults write com.apple.Finder AppleShowAllFiles NO
2:KillAll Finder
5:etc :等等【etcetera的缩写】
6:
使用adb查看手机log:adb logcat
7:
Mac清屏命令:cammand+k
Linux清屏命令:ctrl+l
Windows清屏命令:cls
8:Mac 终端命令大全:https://www.jianshu.com/p/3291de46f3ff