Git常用命令

Git

Git是什么?

Git是目前世界上最先进的分布式版本控制系统
由于使用的mac系统,mac默认安装了Git。可以通过下面命令,在terminate确认是否安装了:

1
git

如果出现了The program ‘git’ is currently not installed. You can install it by typing:提示则表示没有安装,使用:

1
sudo apt-get install git

输入密码即可以等待安装成功。

Git常用命令
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
1. git clone <https,ssh项目的地址>  (表示clone所有的分支)
example: git clone http://git.husor.com.cn/ios/beibei.git

2. git clone -b <分支名称> <https,ssh项目的地址> (表示clone某一个分支)
example: git clone -b release/v4.0.0 http://git.husor.com.cn/ios/beibei.git

3. git branch -r (查看当前项目所有的分支)
example: git branch -r
origin/HEAD -> origin/master
origin/beibei_pod
origin/develop_merge_to_pods
origin/feature/brand_martshow_4.0
origin/feature/develop_4.0.1
origin/feature/lyd_chaozhi
origin/release/v4.0.0
......
4. git checkout <分支名称> (表示检出新的远程分支到本地)
example: git checkout feature/martshow_peel
Branch feature/martshow_peel set up to track remote branch feature/martshow_peel from origin.
Switched to a new branch 'feature/martshow_peel'
5. git commit -a (提交本地的修改文件到暂存区,这个时候会默认调用vim编辑器,输入提交信息);也可以使用git commit -a -m "commit info"
example1: git commit -a

example2: git commit -a -m ".gitignore文件"

如果出现:(表示没有跟踪到的问题)
Untracked files:
BeiBeiAPP.xcodeproj/xcshareddata/
这种类型行的问题,则需要使用git add BeiBeiAPP.xcodeproj/xcshareddata/命令后重新提交即可
6. git push <远程分支> (表示将本地修改的暂存区的内容提交到对应的远程分支)
example: git push feature/martshow_peel
7. git merge <远程分支> (表示从远程分支拉取代码合并到本地)
example: git merge release/v4.0.0 (以下的合并存在冲突)
Auto-merging BeiBeiAPP/BeiBei-Info.plist
CONFLICT (content): Merge conflict in BeiBeiAPP/BeiBei-Info.plist
CONFLICT (modify/delete): BeiBeiAPP/BBClasses/C2C(圈儿)/Common(基础)/BBNavigator+C2CNavigator.m deleted in HEAD and modified in release/v4.0.0. Version release/v4.0.0 of BeiBeiAPP/BBClasses/ C2C(圈儿)/Common(基础)/BBNavigator+C2CNavigator.m left in tree.
Auto-merging BeiBeiAPP.xcodeproj/project.pbxproj
Automatic merge failed; fix conflicts and then commit the result.

8. git tag -l
example: iMac-tortoise:BBCore tianww$ git tag -l
9. git branch [name] (基于当前分支创建本地分之,name分之名称)
example: git branch feature/tianww
10. git push origin [localBranchName]:[branchName](提交本地分支到远程分支)
example: git push origin feature/tianww:feature/tianww

11. git rm -r [filesName] //删除filesName文件所有的文件包含文件夹
example: git rm -r View//删除View文件夹下所有的内容
12.

高级篇

1
2
3
4
5
1. git status (查看当前所有文件的状态)
2. git log(查看提交的log)
3. git reset --hard (reset本地的所有文件,不保留修改untrack的文件)
4. git checkout .(本地所有没有提交的,都返回到原来状态)
5. git diff(查看详细的修改文件代码)
Git常用的工具

SourceTree(推荐,appstore上面即可下载,简单实用功能强大)

Tower (强大,但是要钱)

GitBash

EGit

参考

1.Git命令总结(本地仓库篇)

2.Git常用操作命令