如何使用配置GitHub

Coding Alan 7年前 (2016-11-30) 4137次浏览 0个评论 扫描二维码

Git在Linux上的安装非常简单,直接运行yum install git -y(或sudo apt-get install git,取决于您使用CentOS或Ubuntu等Linux系统)。

通过mkdir proj新建一个项目目录(如/opt/proj),切换到这个目录cd proj, git init进行初始化。命令行提示

Initialized empty Git repository in /opt/proj/.git/

此时运行ls -a可发现目录下有一个隐藏目录.git。

上述/opt/proj/被称作工作区,通过git add指令添加后进入暂存区(stage),git commit之后进入版本库(master)

常用命令
git status
git add 文件名
git checkout 文件名  放弃最近一次修改
git diff 文件名 可查看是否有修改
git commit ([-a] -m “”) -a自动跟踪
git config –global user.name “Alan Hou”
git config –global user.email “info@alanhou.org”
git log (-p) 查看提交的日志(–pretty=oneline)
git reset –hard HEAD^返回上一个版本,HEAD~100指回退到前100个版本,如果在–hard后接提交记录SHA1加密的前几个字符(commit id)即可回退到相应的版本
git reset HEAD filename 回退暂存区的修改到工作区
git reflog 回退后再通git log看到被回退的版本,需要使用git reflog查看
git checkout — filename 放弃修改
git checkout -b dev 创建一个分支dev(git checkout master可以切换分支,git branch可查看的有分支及当前分支)
git checkout -b branch-name origin/branch-name在本地创建和远程分支对应的分支
git branch –set-upstream branch-name origin/branch-name建立本地分支和远程分支的关联
git branch -d dev删除分支(-D强行删除)
git merge dev将dev上的文件合并到当前分支(master)中–no-ff参数表示普通模式合并,默认是fast forward
git rm 删除文件(之后需要执行git commit)
ssh-keygen -t rsa -C “youremail@example.com” 创建公钥、私钥,可以把id_rsa.pub中的内容添加到github上,然后使用如下指令上传(origin可以修改,learngit为在github上创建的仓库名称,alanhou7请修改为你自己的账号,仅第一次需添加-u的参数)
git stash (list pop apply)储存当前分支,在其它地方修改完内容再pop接着进行分支上的开发
git tag v1.0 给当前版本打标签(还可以使用git tag v1.1 7e20928来对某一指定版本打标签,其中7e20928为commit_id)
git tag -a <tagname> -m “blablabla…”可以指定标签信息
git tag -s <tagname> -m “blablabla…”可以用PGP签名标签;
git show tagname 可以查看标签信息
git push origin <tagname>向远程推送指定标签
git push origin –tags向远程推送所有未推送标签
git tag -d v1.0删除本地标签,接着执行git push origin :refs/tags/v1.0删除远程标签

git config –global alias.st status 添加别名,如git st作为git status的别名

.gitignore 在该文件中编辑排除带有敏感信息等文件不执行上传

tig插件

git config –global core.editor vim 【写入的配置可在.git/config文件中查看】
git config –global alias.ci “commit -a -y”(设置别名ci)

常见问题

1、warning: CRLF will be replaced by LF…

执行 git config core.autocrlf true

或使用git config –global core.safecrlf false直接关闭提示

CR = Carriage Return and LF = Line Feed, two expressions have their roots in the old typewriters / TTY. LF moved the paper up (but kept the horizontal position identical) and CR brought back the “carriage” so that the next character typed would be at the leftmost position on the paper (but on the same line).

2、每次连接都需要输入用户名密码

3、解决project.pbxproj冲突

4、error: You have not concluded your merge (MERGE_HEAD exists).

5、GitLab使用非标准端口(如8000)跳转问题

6、撤销对远程代码的提交

7、[git] fatal: Exiting because of an unresolved conflict.

8、Gitlab 数据备份、还原

 

喜欢 (0)
[]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址