美文网首页
Git(备忘录)

Git(备忘录)

作者: Nidalee丶 | 来源:发表于2015-12-21 20:14 被阅读53次
  • 常见命令

1.初始化一个代码仓库
git init
2.如果使用git必须给git配置一个用户名和邮箱
给当前的git仓库配置一个用户名和邮箱
git config user.name “XXX”
git config user.email “XXX”
配置一个全局的用户名和邮箱
git config —global user.name “XXX”
git config —global user.email “XXX”
3.初始化项目
touch main.m : 创建了main.m
git add main.m : 将新添加的文件或者修改的文件添加到暂存区
git commit -m “初始化项目”
git add . : 将所有没有被添加到暂存区或者代码仓库的文件添加到暂存区
注意:无论是新添加的文件或者修改的文件,都需要先通过add命令添加到暂存区中,之后再通过commit命令添加到本地仓库中
4.查看文件的状态 git status
红色 : 新创建的文件或者被修改的文件,没有被添加到暂存区
绿色 : 表示文件在暂存区,但是没有被添加到本地仓库中
5.给命令起别名
git config alias.st “status”
git config alias.ci “commit -m”
git config —global alias.st “status”
6.git删除文件
git rm 文件名
7.查看版本号
git log
git reflog
git config --global alias.lg "log --color --graph -
8.git的版本号是由sha1算法生成40位的哈希值
9.版本回退
git reset —hard HEAD : 回退到当前的版本
git reset —hard HEAD^ : 回退到上一个版本
git reset —hard HEAD^^ : 回退到上上个版本
git reset —hard HEAD~100 : 回退到前100版本
git reset -hard 版本号(前5位)

  • 团队(共享版本库)

1.初始项目
git init —bare
2.项目经理将共享版本库的内容先下载下来
git clone 地址
3.添加需要忽略的文件
touch .gitignore
去github上搜索.gitignore->Objective-C
git add .gitignore
git commit -m “添加了需要忽略的文件”
4.项目经理初始化项目
git commit -m “初始化项目”—>提交到本地代码仓库
5.将项目push远程仓库中
git push origin
6.当源代码管理是使用GIT,并且在Xcode进行多人开发的操作
注意:当使用GIT,项目中用到了静态库就不需要通过命令行进行添加

  • 版本备份

1.1.0版本开发完成,之后对1.0版本进行备份
git tag -a weibo1.0 -m “这个是1.0版本” : 给某一个版本打上标签
git tag : 查看所有的标签
2.需要将1.0版本的标签,push到服务器
git push origin weibo1.0
3.继续开发2.0版本
4.发现1.0版本有bug,从标签里面clone 1.0版本,从标签创建一个fixbug分支,在分支中修复bug
git clone 共享版本库
git checkout weibo1.0(标签的名称)
git checkout -b weibo1.1fixbug(分支名称)
5.修复后的版本上传AppStore/将1.0fixbug进行备份/将1.0fixbug版本和2.0版本进行合并
git tag -a weibo1.1 -m “这个是修复了1.0版本bug的1.1版本”
git tag
git push origin weibo1.1
将子分支中代码合并到主分支,pull—>weibo1.1fixbug—>push master—>其它同事更新
6.删除分支
git branch -r
git branch -r -d 分支名称

  • 将代码托管至别人的服务器上

1.Github
创建Github上的仓库

  1. HTTPS : http + SSL
  2. SSH : 公钥和私钥—>settings—>SSH Keys—>生成公钥和私钥
    删除代码仓库
    可以给别人的代码提比较功能/对别人的代码重构:fork—>pull Request
    issues : 给框架作者提问题
    2.OSChina(Github上面项目不能私有化:交钱可以)
    创建代码仓库
    HTTPS/SSH
    .gitignore不够完整 : 手动添加完成
    如果项目想要多人开发:管理—>成员管理—>添加成员:让新人注册一个OSChina
僵尸

Last login: Fri Dec 25 08:27:25 on console
dllodeMac-mini-362:~ _Nidalee$ git clone https://git.oschina.net/nidalee/glone.git
Cloning into 'glone'...
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
Checking connectivity... done.
dllodeMac-mini-362:~ _Nidalee$ cd glone/
dllodeMac-mini-362:glone _Nidalee$** ls**
README.md
dllodeMac-mini-362:glone _Nidalee$ defaults write com.apple.finder AppleShowAllFiles -bool true
dllodeMac-mini-362:glone _Nidalee$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Untracked files:
(use "git add <file>..." to include in what will be committed)

"_Block\345\203\265\345\260\270\347\211\210/"

nothing added to commit but untracked files present (use "git add" to track)
dllodeMac-mini-362:glone _Nidalee$ git add -A
dllodeMac-mini-362:glone _Nidalee$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)

new file:   "_Block\345\203\265\345\260\270\347\211\210/_Block\345\203\265\345\260\270\347\211\210.xcodeproj/project.pbxproj"
new file:   "_Block\345\203\265\345\260\270\347\211\210/_Block\345\203\265\345\260\270\347\211\210.xcodeproj/project.xcworkspace/contents.xcworkspacedata"
new file:   "_Block\345\203\265\345\260\270\347\211\210/_Block\345\203\265\345\260\270\347\211\210.xcodeproj/project.xcworkspace/xcuserdata/_Nidalee.xcuserdatad/UserInterfaceState.xcuserstate"
new file:   "_Block\345\203\265\345\260\270\347\211\210/_Block\345\203\265\345\260\270\347\211\210.xcodeproj/xcuserdata/_Nidalee.xcuserdatad/xcschemes/_Block\345\203\265\345\260\270\347\211\210.xcscheme"
new file:   "_Block\345\203\265\345\260\270\347\211\210/_Block\345\203\265\345\260\270\347\211\210.xcodeproj/xcuserdata/_Nidalee.xcuserdatad/xcschemes/xcschememanagement.plist"
new file:   "_Block\345\203\265\345\260\270\347\211\210/_Block\345\203\265\345\260\270\347\211\210/AppDelegate.h"
new file:   "_Block\345\203\265\345\260\270\347\211\210/_Block\345\203\265\345\260\270\347\211\210/AppDelegate.m"
new file:   "_Block\345\203\265\345\260\270\347\211\210/_Block\345\203\265\345\260\270\347\211\210/ArrayDataSource.h"
new file:   "_Block\345\203\265\345\260\270\347\211\210/_Block\345\203\265\345\260\270\347\211\210/ArrayDataSource.m"
new file:   "_Block\345\203\265\345\260\270\347\211\210/_Block\345\203\265\345\260\270\347\211\210/Assets.xcassets/AppIcon.appiconset/Contents.json"
new file:   "_Block\345\203\265\345\260\270\347\211\210/_Block\345\203\265\345\260\270\347\211\210/Base.lproj/LaunchScreen.storyboard"
new file:   "_Block\345\203\265\345\260\270\347\211\210/_Block\345\203\265\345\260\270\347\211\210/Base.lproj/Main.storyboard"
new file:   "_Block\345\203\265\345\260\270\347\211\210/_Block\345\203\265\345\260\270\347\211\210/Info.plist"
new file:   "_Block\345\203\265\345\260\270\347\211\210/_Block\345\203\265\345\260\270\347\211\210/ViewController.h"
new file:   "_Block\345\203\265\345\260\270\347\211\210/_Block\345\203\265\345\260\270\347\211\210/ViewController.m"
new file:   "_Block\345\203\265\345\260\270\347\211\210/_Block\345\203\265\345\260\270\347\211\210/main.m"
new file:   "_Block\345\203\265\345\260\270\347\211\210/_Block\345\203\265\345\260\270\347\211\210Tests/Info.plist"
new file:   "_Block\345\203\265\345\260\270\347\211\210/_Block\345\203\265\345\260\270\347\211\210Tests/_Block___Tests.m"
new file:   "_Block\345\203\265\345\260\270\347\211\210/_Block\345\203\265\345\260\270\347\211\210UITests/Info.plist"
new file:   "_Block\345\203\265\345\260\270\347\211\210/_Block\345\203\265\345\260\270\347\211\210UITests/_Block___UITests.m"

dllodeMac-mini-362:glone _Nidalee$ git commit -m "提交了工程”
[master 2312b0d] 提交了工程
20 files changed, 1184 insertions(+)
create mode 100644 "_Block\345\203\265\345\260\270\347\211\210/_Block\345\203\265\345\260\270\347\211\210.xcodeproj/project.pbxproj"
create mode 100644 "_Block\345\203\265\345\260\270\347\211\210/_Block\345\203\265\345\260\270\347\211\210.xcodeproj/project.xcworkspace/contents.xcworkspacedata"
create mode 100644 "_Block\345\203\265\345\260\270\347\211\210/_Block\345\203\265\345\260\270\347\211\210.xcodeproj/project.xcworkspace/xcuserdata/_Nidalee.xcuserdatad/UserInterfaceState.xcuserstate"
create mode 100644 "_Block\345\203\265\345\260\270\347\211\210/_Block\345\203\265\345\260\270\347\211\210.xcodeproj/xcuserdata/_Nidalee.xcuserdatad/xcschemes/_Block\345\203\265\345\260\270\347\211\210.xcscheme"
create mode 100644 "_Block\345\203\265\345\260\270\347\211\210/_Block\345\203\265\345\260\270\347\211\210.xcodeproj/xcuserdata/_Nidalee.xcuserdatad/xcschemes/xcschememanagement.plist"
create mode 100644 "_Block\345\203\265\345\260\270\347\211\210/_Block\345\203\265\345\260\270\347\211\210/AppDelegate.h"
create mode 100644 "_Block\345\203\265\345\260\270\347\211\210/_Block\345\203\265\345\260\270\347\211\210/AppDelegate.m"
create mode 100644 "_Block\345\203\265\345\260\270\347\211\210/_Block\345\203\265\345\260\270\347\211\210/ArrayDataSource.h"
create mode 100644 "_Block\345\203\265\345\260\270\347\211\210/_Block\345\203\265\345\260\270\347\211\210/ArrayDataSource.m"
create mode 100644 "_Block\345\203\265\345\260\270\347\211\210/_Block\345\203\265\345\260\270\347\211\210/Assets.xcassets/AppIcon.appiconset/Contents.json"
create mode 100644 "_Block\345\203\265\345\260\270\347\211\210/_Block\345\203\265\345\260\270\347\211\210/Base.lproj/LaunchScreen.storyboard"
create mode 100644 "_Block\345\203\265\345\260\270\347\211\210/_Block\345\203\265\345\260\270\347\211\210/Base.lproj/Main.storyboard"
create mode 100644 "_Block\345\203\265\345\260\270\347\211\210/_Block\345\203\265\345\260\270\347\211\210/Info.plist"
create mode 100644 "_Block\345\203\265\345\260\270\347\211\210/_Block\345\203\265\345\260\270\347\211\210/ViewController.h"
create mode 100644 "_Block\345\203\265\345\260\270\347\211\210/_Block\345\203\265\345\260\270\347\211\210/ViewController.m"
create mode 100644 "_Block\345\203\265\345\260\270\347\211\210/_Block\345\203\265\345\260\270\347\211\210/main.m"
create mode 100644 "_Block\345\203\265\345\260\270\347\211\210/_Block\345\203\265\345\260\270\347\211\210Tests/Info.plist"
create mode 100644 "_Block\345\203\265\345\260\270\347\211\210/_Block\345\203\265\345\260\270\347\211\210Tests/_Block___Tests.m"
create mode 100644 "_Block\345\203\265\345\260\270\347\211\210/_Block\345\203\265\345\260\270\347\211\210UITests/Info.plist"
create mode 100644 "_Block\345\203\265\345\260\270\347\211\210/_Block\345\203\265\345\260\270\347\211\210UITests/_Block___UITests.m"
dllodeMac-mini-362:glone _Nidalee$ git pull
Already up-to-date.
dllodeMac-mini-362:glone _Nidalee$ git push
warning: push.default is unset; its implicit value has changed in
Git 2.0 from 'matching' to 'simple'. To squelch this message
and maintain the traditional behavior, use:

git config --global push.default matching

To squelch this message and adopt the new behavior now, use:

git config --global push.default simple

When push.default is set to 'matching', git will push local branches
to the remote branches that already exist with the same name.

Since Git 2.0, Git defaults to the more conservative 'simple'
behavior, which only pushes the current branch to the corresponding
remote branch that 'git pull' uses to update the current branch.

See 'git help config' and search for 'push.default' for further information.
(the 'simple' mode was introduced in Git 1.7.11. Use the similar mode
'current' instead of 'simple' if you sometimes use older versions of Git)

Username for 'https://git.oschina.net': nidalee
Password for 'https://nidalee@git.oschina.net': 密码
Counting objects: 35, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (30/30), done.
Writing objects: 100% (35/35), 20.04 KiB | 0 bytes/s, done.
Total 35 (delta 4), reused 0 (delta 0)
To https://git.oschina.net/nidalee/glone.git
8368130..2312b0d master -> master
dllodeMac-mini-362:glone _Nidalee$

完成情况

相关文章

  • Git 备忘录

    Git 备忘录 -- Git 查看记录 一行展示log日志 查看命令历史 Git 回退 从本地仓库撤销(使用了gi...

  • Git 备忘录

    git commit : a new commitgit branch : a new branchmaster ...

  • git备忘录

  • Git备忘录

    删除远程分支git push origin --delete 创建本地分支git checkout -b iss5...

  • git备忘录

    基本命令 创建一个空的版本库 将文件添加到版本库的索引中 创建一个新的提交记录(-m之后是提交留言) 查看提交相关...

  • Git备忘录

    1. 配置 git config user.email your_mail@nsn.com git config ...

  • Git 备忘录

    工作流 你的本地仓库由 git 维护的三棵“树”组成。第一个是你的 工作目录,它持有实际文件;第二个是 暂存区(I...

  • Git(备忘录)

    常见命令 1.初始化一个代码仓库git init2.如果使用git必须给git配置一个用户名和邮箱给当前的git仓...

  • git备忘录

    仅拉取需要的部分( Sparse Checkout)创建仓库mkdir test && cd test && gi...

  • git备忘

    git备忘录 官网教程 “origin” 并无特殊含义远程仓库名字 “origin” 与分支名字 “master”...

网友评论

      本文标题:Git(备忘录)

      本文链接:https://www.haomeiwen.com/subject/ylbmhttx.html