Git

$ git init
Initialized empty Git repository in /Users/tianqixin/www/runoob/.git/

现在你可以看到在你的项目中生成了 .git 这个子目录,这就是你的 Git 仓库了,所有有关你的此项目的快照数据都存放在这里。

.git 默认是隐藏的,可以用 ls -a 命令查看:

git clone https://github.com/tianqixin/runoob-git-test

 

 

Git 全局设置:

git config --global user.name "kingstudy"
git config --global user.email "273632159@qq.com"

创建 git 仓库:

mkdir wind-sleeve
cd wind-sleeve
git init
touch README.md
git add README.md
git commit -m "first commit"
git remote add origin https://gitee.com/kingstudy/wind-sleeve.git
git push -u origin master

已有仓库?

cd existing_git_repo
git remote add origin https://gitee.com/kingstudy/wind-sleeve.git
git push -u origin master
Git 工作区、暂存区和版本库
基本概念
工作区:就是你在电脑里能看到的目录。
暂存区:英文叫stage, 或index。一般存放在 ".git目录下" 下的index文件(.git/index)中,所以我们把暂存区有时也叫作索引(index)。
版本库:工作区有一个隐藏目录.git,这个不算工作区,而是Git的版本库。
Git 工作区、暂存区和版本库
git add
内容写入缓存区 ->添加所有文件  git add .  ->或者添加指定文件 git add 文件名
撤销所有缓存的内容 git reset HEAD . 或者撤销指定文件的缓存 git reset 文件名
git reset HEAD
git reset HEAD 命令用于取消已缓存的内容 简而言之,执行 git reset HEAD 以取消之前 git add 添加,但不希望包含在下一提交快照中的缓存。
git commit
使用 git add 命令将想要快照的内容写入缓存区, 而执行 git commit 将缓存区内容添加到仓库中
将缓存区内容添加到仓库中  git commit -m '第一次版本提交'
 
git status
查看项目的当前git状态  git status  或 git status -s   -> 
加了 -s 参数,以获得简短的结果输出。如果没加该参数会详细输出内容
"A" 状态的意思是,这个文件成功添加到缓存    红色为警告 绿色为执行正确
"AM" 状态的意思是,这个文件在我们将它添加到缓存之后又有改动。改动后我们再执行 git add 命令将其添加到缓存中
"M" 状态的意思是 红色 M 添加到缓存之后又从缓存中撤销  绿色 M 添加到缓存之后修改完又再次成功添加到缓存
git diff
执行 git diff 来查看执行 git status 的结果的详细信息   git diff显示到具体哪行改动 git status显示到哪个文件有改动
git diff 命令显示已写入缓存与已修改但尚未写入缓存的改动的区别。git diff 有两个主要的应用场景
    •    尚未缓存的改动:git diff
    •    查看已缓存的改动: git diff --cached
    •    查看已缓存的与未缓存的所有改动:git diff HEAD

git rm
如果只是简单地从工作目录中手工删除文件,运行 git status 时就会在 Changes not staged for commit 的提示。
要从 Git 中移除某个文件,就必须要从已跟踪文件清单中移除,然后提交。可以用以下命令完成此项工作
git rm <file>
如果删除之前修改过并且已经放到暂存区域的话,则必须要用强制删除选项 -f
git rm -f <file>
如果把文件从暂存区域移除,但仍然希望保留在当前工作目录中,换句话说,仅是从跟踪清单中删除,使用 --cached 选项即可

git rm --cached <file>
可以递归删除,即如果后面跟的是一个目录做为参数,则会递归删除整个目录中的所有子目录和文件:
进入某个目录中,执行此语句,会删除该目录下的所有文件和子目录。
git rm –r *
git mv
git mv 命令用于移动或重命名一个文件、目录、软连接

git mv README  README.md
Git 基本操作
创建分支
git branch (branchname)
切换分支
git checkout (branchname)
当你切换分支的时候,Git 会用该分支的最后提交的快照替换你的工作目录的内容, 所以多个分支不需要多个目录。
合并分支
git merge 
列出分支基本命令 没有参数时,git branch 会列出你在本地的分支
git branch
删除分支命令
git branch -d (branchname)
分支合并
一旦某分支有了独立内容,你终究会希望将它合并回到你的主分支。 你可以使用以下命令将任何分支合并到当前分支中去
git merge(branchname)
Git 分支管理
在使用 Git 提交了若干更新之后,又或者克隆了某个项目,想回顾下提交历史,我们可以使用 git log 命令查看
git log
我们可以用 --oneline 选项来查看历史记录的简洁的版本。
git log --oneline
我们还可以用 --graph 选项,查看历史中什么时候出现了分支、合并。
git log --graph
如果只想查找指定用户的提交日志可以使用命令:git log --author , 例如,比方说我们要找 Git 源码中 Linus 提交的部分
git log --author=ios --oneline
Git 查看提交历史
如果你达到一个重要的阶段,并希望永远记住那个特别的提交快照,你可以使用 git tag 给它打上标签。
比如说,我们想为我们的 runoob 项目发布一个"1.0"版本。 我们可以用 git tag -a v1.0 命令给最新一次提交打上(HEAD)"v1.0"的标签。
-a 选项意为"创建一个带注解的标签"。 不用 -a 选项也可以执行的,但它不会记录这标签是啥时候打的,谁打的,也不会让你添加个标签的注解。 我推荐一直创建带注解的标签。

给最新一次提交打上(HEAD)"v2.0”的标签
git tag -a v2.0

给历史提交打上(HEAD)"v1.0"的标签 85fc7e7位历史节点id
git tag -a v1.0 85fc7e7

如果我们要查看所有标签可以使用以下命令:
git tag

PGP签名标签命令
git tag -s <tagname> -m "runoob.com标签"
Git 标签
查看当前配置有哪些远程仓库 
git remote
执行时加上 -v 参数,你还可以看到每个别名的实际链接地址
git remote -v

Git 有两个命令用来提取远程仓库的更新。
1、从远程仓库下载新分支与数据:
git fetch
该命令执行完后需要执行git merge 远程分支到你所在的分支。

2、从远端仓库提取数据并尝试合并到当前分支:
git merge
该命令就是在执行 git fetch 之后紧接着执行 git merge 远程分支到你所在的任意分支。
假设你配置好了一个远程仓库,并且你想要提取更新的数据,你可以首先执行 git fetch [alias] 告诉 Git 去获取它有你没有的数据,然后你可以执行 git merge [alias]/[branch] 以将服务器上的任何更新(假设有人这时候推送到服务器了)合并到你的当前分支。

删除远程仓库你可以使用命令
git remote rm [别名]
# 删除仓库 origin2
$ git remote rm origin2
Git 远程仓库
# .gitignore file for Xcode4 and Xcode5 Source projects
#
# Apple bugs, waiting for Apple to fix/respond:
#
#    15564624 - what does the xccheckout file in Xcode5 do? Where's the documentation?
#
# Version 2.6
# For latest version, see: http://stackoverflow.com/questions/49478/git-ignore-file-for-xcode-projects
#
# 2015 updates:
# - Fixed typo in "xccheckout" line - thanks to @lyck for pointing it out!
# - Fixed the .idea optional ignore. Thanks to @hashier for pointing this out
# - Finally added "xccheckout" to the ignore. Apple still refuses to answer support requests about this, but in practice it seems you should ignore it.
# - minor tweaks from Jona and Coeur (slightly more precise xc* filtering/names)
# 2014 updates:
# - appended non-standard items DISABLED by default (uncomment if you use those tools)
# - removed the edit that an SO.com moderator made without bothering to ask me
# - researched CocoaPods .lock more carefully, thanks to Gokhan Celiker
# 2013 updates:
# - fixed the broken "save personal Schemes"
# - added line-by-line explanations for EVERYTHING (some were missing)
#
# NB: if you are storing "built" products, this WILL NOT WORK,
# and you should use a different .gitignore (or none at all)
# This file is for SOURCE projects, where there are many extra
# files that we want to exclude
#
#########################

#####
# OS X temporary files that should never be committed
#
# c.f. http://www.westwind.com/reference/os-x/invisibles.html

.DS_Store

# c.f. http://www.westwind.com/reference/os-x/invisibles.html

.Trashes

# c.f. http://www.westwind.com/reference/os-x/invisibles.html

*.swp

#
# *.lock - this is used and abused by many editors for many different things.
#    For the main ones I use (e.g. Eclipse), it should be excluded 
#    from source-control, but YMMV.
#   (lock files are usually local-only file-synchronization on the local FS that should NOT go in git)
# c.f. the "OPTIONAL" section at bottom though, for tool-specific variations!
#
# In particular, if you're using CocoaPods, you'll want to comment-out this line:
*.lock


#
# profile - REMOVED temporarily (on double-checking, I can't find it in OS X docs?)
#profile


####
# Xcode temporary files that should never be committed
# 
# NB: NIB/XIB files still exist even on Storyboard projects, so we want this...

*~.nib


####
# Xcode build files -
#
# NB: slash on the end, so we only remove the FOLDER, not any files that were badly named "DerivedData"

DerivedData/

# NB: slash on the end, so we only remove the FOLDER, not any files that were badly named "build"

build/


#####
# Xcode private settings (window sizes, bookmarks, breakpoints, custom executables, smart groups)
#
# This is complicated:
#
# SOMETIMES you need to put this file in version control.
# Apple designed it poorly - if you use "custom executables", they are
#  saved in this file.
# 99% of projects do NOT use those, so they do NOT want to version control this file.
#  ..but if you're in the 1%, comment out the line "*.pbxuser"

# .pbxuser: http://lists.apple.com/archives/xcode-users/2004/Jan/msg00193.html

*.pbxuser

# .mode1v3: http://lists.apple.com/archives/xcode-users/2007/Oct/msg00465.html

*.mode1v3

# .mode2v3: http://lists.apple.com/archives/xcode-users/2007/Oct/msg00465.html

*.mode2v3

# .perspectivev3: http://stackoverflow.com/questions/5223297/xcode-projects-what-is-a-perspectivev3-file

*.perspectivev3

#    NB: also, whitelist the default ones, some projects need to use these
!default.pbxuser
!default.mode1v3
!default.mode2v3
!default.perspectivev3


####
# Xcode 4 - semi-personal settings
#
# Apple Shared data that Apple put in the wrong folder
# c.f. http://stackoverflow.com/a/19260712/153422
#     FROM ANSWER: Apple says "don't ignore it"
#     FROM COMMENTS: Apple is wrong; Apple code is too buggy to trust; there are no known negative side-effects to ignoring Apple's unofficial advice and instead doing the thing that actively fixes bugs in Xcode
# Up to you, but ... current advice: ignore it.
*.xccheckout

#
#
# OPTION 1: ---------------------------------
#     throw away ALL personal settings (including custom schemes!
#     - unless they are "shared")
# As per build/ and DerivedData/, this ought to have a trailing slash
#
# NB: this is exclusive with OPTION 2 below
xcuserdata/

# OPTION 2: ---------------------------------
#     get rid of ALL personal settings, but KEEP SOME OF THEM
#     - NB: you must manually uncomment the bits you want to keep
#
# NB: this *requires* git v1.8.2 or above; you may need to upgrade to latest OS X,
#    or manually install git over the top of the OS X version
# NB: this is exclusive with OPTION 1 above
#
#xcuserdata/**/*

#     (requires option 2 above): Personal Schemes
#
#!xcuserdata/**/xcschemes/*

####
# Xcode 4 workspaces - more detailed
#
# Workspaces are important! They are a core feature of Xcode - don't exclude them :)
#
# Workspace layout is quite spammy. For reference:
#
# /(root)/
#   /(project-name).xcodeproj/
#     project.pbxproj
#     /project.xcworkspace/
#       contents.xcworkspacedata
#       /xcuserdata/
#         /(your name)/xcuserdatad/
#           UserInterfaceState.xcuserstate
#     /xcshareddata/
#       /xcschemes/
#         (shared scheme name).xcscheme
#     /xcuserdata/
#       /(your name)/xcuserdatad/
#         (private scheme).xcscheme
#         xcschememanagement.plist
#
#

####
# Xcode 4 - Deprecated classes
#
# Allegedly, if you manually "deprecate" your classes, they get moved here.
#
# We're using source-control, so this is a "feature" that we do not want!

*.moved-aside

####
# OPTIONAL: Some well-known tools that people use side-by-side with Xcode / iOS development
#
# NB: I'd rather not include these here, but gitignore's design is weak and doesn't allow
#     modular gitignore: you have to put EVERYTHING in one file.
#
# COCOAPODS:
#
# c.f. http://guides.cocoapods.org/using/using-cocoapods.html#what-is-a-podfilelock
# c.f. http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control
#
#!Podfile.lock
#
# RUBY:
#
# c.f. http://yehudakatz.com/2010/12/16/clarifying-the-roles-of-the-gemspec-and-gemfile/
#
#!Gemfile.lock
#
# IDEA:
#
# c.f. https://www.jetbrains.com/objc/help/managing-projects-under-version-control.html?search=workspace.xml
# 
#.idea/workspace.xml
#
# TEXTMATE:
#
# -- UNVERIFIED: c.f. http://stackoverflow.com/a/50283/153422
#
#tm_build_errors

####
# UNKNOWN: recommended by others, but I can't discover what these files are
#
Git过滤文件详细描述View Code
#CocoaPods
Pods/
!Podfile
!Podfile.lock



#Xcode
.DS_Store

#Build generated
build/
DerivedData/

## Various settings
*.pbxuser!default.pbxuser
*.mode1v3!default.mode1v3
*.mode2v3!default.mode2v3
*.perspectivev3!default.perspectivev3
xcuserdata/

## Other
*.moved-aside
*.xcuserstate
*.xccheckout
*.xcworkspace

## Obj-C/Swift specific
*.hmap
*.ipa
*.dSYM.zip
*.dSYM
.gitignore文件

 

Git 本地git提交

1.写入本地缓存区

git add .

2.将本地缓存区内容提交到本地仓库中 

git commit -m '第一次版本提交'

3.查看项目的当前git执行状态与结果 

git status

1.从远程仓库拉取最新数据到本地  

git fetch 

2.与本地仓库数据合并

git merge 

3.查看项目的当前git执行状态与结果 

git status


Git 本地分支管理

查看分支

git branch

创建分支

git branch (branchname)

切换分支

git checkout (branchname)

合并分支

git merge (branchname)

删除分支

git branch -d (branchname)

 

组合查看历史git版本信息描述

git log --oneline --decorate --graph

 

给最新一次提交打上(HEAD)"v2.0”的标签

git tag -a v2.0

 
给历史提交打上(HEAD)"v1.0"的标签 85fc7e7 未历史某个节点id

git tag -a v1.0 85fc7e7


修改全局仓库的用户名和邮箱
git config --global user.name  “用户名”
git config --global user.email   “邮箱”

Git拉取远程分支到本地
//创建远程连接
 
git remote add origin https://gitee.com/kingstudy/watertest.git
 
//本地创建分支并与远程分支联系
 
git checkout -b develop origin/develop
Git常用命令

 

 

 

Git常见冲突问题解决

问题1 The file couldn’t be opened

  1. 右击项目 xx.xcodeproj 选择显示包内容,打开第一个文件 project.pbsproj
  2. command+f 输入=== 查找有冲突的地方,
  3. 解决冲突。
  4. 如果是.pch文件路径冲突建议 $(SRCROOT)/项目名/PrefixHeader.pch

问题2 clang: error: no such file or directory: '/Users/HELLOWORLD/Desktop/防水最新版/WaterProofer/HireLeakageModel.m'

clang: error: no input files

1. TARGETS -> Build Phases -> Search HireLeakageModel.m

git reset --hard 1754d3b回滚到指定版本

posted @ 2019-09-09 22:59  &#127810;浪迹天涯&#127810;  阅读(169)  评论(0编辑  收藏  举报