Git 笔记

Git教程推荐廖雪峰老师 Git教程

在实践中积累熟悉Git命令,有效提高工作效率。


初始化本地库:git init

 

添加远程库:git remote add origin URL

 

(非必要)克隆远程库:git clone URL

 

*新建一个本地分支,并切换到该分支上:

git checkout -b [branch-name]

 

拉取所有分支:git pull

 

拉取远程分支 到本地: git pull <远程> <分支>

 

(待验证)拉取远程分支 到本地:

git fetch origin 远程分支名:本地分支名

 

切换分支:git checkout [branch-name]

 

创建远程分支(本地分支push到远程):$ git push origin [branch-name]

 

推送分支:(前提是已建立本地与远程分支的关系)

$ git push origin [branch-name]

 

 

4、推送本地分支local_branch到远程分支 remote_branch并建立关联关系

 

a.远程已有remote_branch分支并且已经关联本地分支local_branch且本地已经切换到local_branch

 

git push

 

b.远程已有remote_branch分支但未关联本地分支local_branch且本地已经切换到local_branch

 

git push -u origin/remote_branch

 

c.远程没有remote_branch分支,本地已经切换到local_branch

 

git push origin local_branch:remote_branch

 

5、删除本地分支local_branch

 

git branch -d local_branch

 

6、删除远程分支remote_branch

 

git push origin :remote_branch (注意origin后的空格)

 

git branch -m | -M oldbranch newbranch 重命名分支,如果newbranch名字分支已经存在,则需要使用-M强制重命名,否则,使用-m进行重命名。

 

 

合并到release

git checkout release

git merge --no-ff origin debug

git push

 

 

HEAD指向的版本就是当前版本,使用命令:

git reset --hard commit_id。

 

穿梭前,用git log可以查看提交历史,以便确定要回退到哪个版本。

 

要重返未来,用git reflog查看命令历史,以便确定要回到未来的哪个版本。

 

 

 git add -A 提交所有变化

 git add -u 提交被修改(modified)和被删除(deleted)文件,不包括新文件(new)

 git add . 提交新文件(new)和被修改(modified)文件,不包括被删除(deleted)文件

 

巧妙利用.gitignore文件的功能,来忽略一些文件

你可能感兴趣的:(Git,博客,csdn,工具)