Git 常用命令

常用命令

1.git init (把目录变成git可以管理的仓库)

2.git add . (把修改的内容提交的暂存区)

3.git commit -m "提交的提示信息" (把修改的内容直接提交到远程仓库)

4.git status (查看是否还有文件没提交)

5.git diff 文件名字 (查看文件修改的详细内容)

6.git clone 远程仓库的地址 (克隆远程仓库的文件)

7.git checkout -b 分支的名字 (克隆远程仓库的文件)

8.git branch (查看分支,当前分支会添加星号)

9.*git merge 分支的名字 (合并分支的名字到我现在所在的分支上 ,把(分支的名字)合并master分支上)

10.git branch -d 分支的名字 (删除(分支的名字)分支)

推送分支就是把该分支上所有本地提交到远程库中,推送时,要指定本地分支,这样,Git就会把该分支推送到远程库对应的远程分支上:

11.*git push origin master (推送)

12.*git checkout 分支的名字 (切换分支)

13 *git pull origin master (master 指定远程仓库的名字 拉取远程仓库的内容"拉去)

冲突解决办法:

查看冲突文件 进行修改冲突

git statu

把远程仓库的数据拉去到本地:

git pull origin dev

获取远端库最新信息:

查询当前远程的版本

$ git remote -v

直接拉取并合并最新代码

$ git pull origin master [示例1:拉取远端origin/master分支并合并到当前分支]
$ git pull origin dev [示例2:拉取远端origin/dev分支并合并到当前分支]

配置用户名和密码

配置用户名和邮箱(全局)

$ git config --global user.name "j***n"
$ git config --global user.email "zh***cn"

用户名和密码存贮的位置是:C:\Users\用户名\.gitconfig  文件

配置用户名和邮箱(在某个特定的项目中)

$ git config user.name "j***n"
$ git config user.email "z****cn"

用户名和密码存贮的位置是:对应的本地仓库的.git文件中的config文件

自己的日常使用

1.写完代码保存
git add .

2.git commit -m "提交的提示信息"

3.切换到master 
git ceckout master

4.拉下来远程仓库的代码
git pull origin master

5.把自己写的代码合并到master分支上
git merge ayune

6.提交到自己的分支
git push origin ayune

7.切换到dev分支
git checkout dev

8.把自己代码合并到dev分支
git merge ayune

9.在把dev分支的代码提交到远程仓库
git push origin dev

10.同步远程分支到本地:
git fetch  

11.连接远程仓库:
git remote add origin + 远程地址

12.忽略文件(添加或略文件:)
.DS_Store
/simplewind/    #表示过滤整个文件夹
/update/
/data/     #表示过滤整个文件夹data
/public/upload/  #忽略目录 upload 下的全部内容
/public/logs/
*.log:          #表示忽略所有 .log 文件
/.idea/          #表示忽略 .idea/目录下的所有文件,过滤整个.idea文件夹;
think
webpack.mix.js
_config.yml
.htaccess
*.txt       #表示过滤所有.txt文件
*.md
*.lock
*.json

13.清除本地库的缓存(谨慎使用):
 git rm -r --cached .

14.这条指令的意思是把远程库中的更新合并到本地库中,-rebase的作用是取消掉本地库中刚刚的commit,并把他们接到更新后的版本库之中。
git pull --rebase origin master

15.报错
warning: adding embedded git repository: cdn_online
hint: You've added another git repository inside your current repository.
hint: Clones of the outer repository will not contain the contents of
hint: the embedded repository and will not know how to obtain it.
hint: If you meant to add a submodule, use:
hint:
hint:   git submodule add <url> cdn_online
hint:
hint: If you added this path by mistake, you can remove it from the
hint: index with:
hint:
hint:   git rm --cached cdn_online
hint:
hint: See "git help submodule" for more information.
报错原因因为同一个文件夹出现了两个.git(两个或则多个git初始化文件)

16.fetch-pack: invalid index-pack output
用原生git命令 ,还是用Sourcetree工具将其中的分支拉取下来报错
fetch-pack: invalid index-pack output
找了很多方法,有说文件夹设置不只读的,然后没有什么用
最后得到结果,是因为 项目体积过大导致报错,所以只需要,浅拉取最后一次提交的就行了
git 命令
git clone -b 分支名 --depth=1 仓库路径

17.查看本地与远程分支的追踪关系
git remote show origin 

18.查看可被清理的分支
git remote prune origin

19.清理该分支
git remote prune origin
posted @ 2021-04-26 11:41  阿钰。  阅读(85)  评论(0)    收藏  举报