git 使用
PS E:\learn\gitProject> ls
目录: E:\learn\gitProject
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 2019/6/20 21:47 412 first.txt
PS E:\learn\gitProject> git status ***********查看git的仓库状态
On branch master
nothing to commit, working tree clean
PS E:\learn\gitProject> git remote add origin git@github.com:jathams/Interview.git ******************将本地仓库链接到远程仓库
fatal: remote origin already exists. *******************origin仓库已经存在
PS E:\learn\gitProject> git remote rm origin ****************删除本地关联的远程仓库
PS E:\learn\gitProject> git remote add origin git@github.com:jathams/Interview.git
PS E:\learn\gitProject> git push -u origin master ---------------------将本地文件提交到远程仓库的master分支
Warning: Permanently added the RSA host key for IP address '13.250.177.223' to the list of known hosts.
Enter passphrase for key '/c/Users/zhangshaobo/.ssh/id_rsa':
To github.com:jathams/Interview.git
! [rejected] master -> master (fetch first) ****************************拒绝提交
error: failed to push some refs to 'git@github.com:jathams/Interview.git'
hint: Updates were rejected because the remote contains work that you do *********************因为你的本地仓库没有更新远程仓库的所有文件
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
PS E:\learn\gitProject> git push --help
PS E:\learn\gitProject> git pull --rebase origin master ******************拉取远程仓库的master分支的所有内容
Enter passphrase for key '/c/Users/zhangshaobo/.ssh/id_rsa':
warning: no common commits
remote: Enumerating objects: 9, done.
remote: Counting objects: 100% (9/9), done.
remote: Compressing objects: 100% (5/5), done.
remote: Total 9 (delta 1), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (9/9), done.
From github.com:jathams/Interview
* branch master -> FETCH_HEAD
* [new branch] master -> origin/master
First, rewinding head to replay your work on top of it...
Applying: first commit
Applying: second edit
PS E:\learn\gitProject> git push -u origin master ***************将本地文件推送到远程
Enter passphrase for key '/c/Users/zhangshaobo/.ssh/id_rsa':
Enumerating objects: 7, done.
Counting objects: 100% (7/7), done.
Delta compression using up to 8 threads
Compressing objects: 100% (5/5), done.
Writing objects: 100% (6/6), 861 bytes | 215.00 KiB/s, done.
Total 6 (delta 0), reused 0 (delta 0)
To github.com:jathams/Interview.git
f3d4083..4a19a54 master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.
PS E:\learn\gitProject> git status *******************查看状态
On branch master
Your branch is up to date with 'origin/master'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed) *****************将修改的文件添加到缓存区
(use "git checkout -- <file>..." to discard changes in working directory) ***************使用git checkout 命令丢弃本地的文件变化内容
modified: first.txt *********************发生改变的文件
no changes added to commit (use "git add" and/or "git commit -a")
PS E:\learn\gitProject> git add .\first.txt ****************将修改的文件提交到缓存区
PS E:\learn\gitProject> git commit .\first.txt -m "third commit" **************************将缓存区的内容提交到本地仓库
[master 49ec139] third commit
1 file changed, 3 insertions(+), 3 deletions(-)
rewrite first.txt (96%)
PS E:\learn\gitProject> git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
(use "git push" to publish your local commits)
nothing to commit, working tree clean
PS E:\learn\gitProject> git push *****************将本地修改推送到远程
Enter passphrase for key '/c/Users/zhangshaobo/.ssh/id_rsa':
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 8 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 290 bytes | 145.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To github.com:jathams/Interview.git
4a19a54..49ec139 master -> master
PS E:\learn\gitProject> git status
On branch master
Your branch is up to date with 'origin/master'.
nothing to commit, working tree clean
PS E:\learn\gitProject>
后续
-
缓存本地文件
git stash git stash list git stash pop git stash drop -
强制远程仓库内容覆盖本地仓库内容
git reset --hard orgin/master -
查看日志
git log --pretty=oneline//在一行内查看日志记录 -
版本区别
git diff local_file -
解决冲突
平时使用git push 之前都会使用git pull先拉取最新的远程仓库内容,并且这个时候最容易发生冲突,拉取后再去查看代码,就会发现 发生冲突的代码中多了几行形如 HEAD code。。。 >>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<< code。。。 一串数字 使用过svn这样的集中式版本控制工具的一看就明白,这里面的代码就是发生冲突的代码块,head代表的是自己本地仓库中最新的代码,而下边的代表的是远程仓库里面的最新代码,你需要做的就是 对这些代码进行取舍,然后保存提交。 -
名词解释
远程服务器:github或者gitlab等 远程仓库:在远程服务器上的仓库 本地仓库:本地的git工作目录 远程仓库名:默认是origin 本地缓冲区:add的区域 远程主分支:master 分支. :branch,可以随便建立,单独开发。一般会分为开发分支,主分支,测试分支,等
博客主要围绕Git使用展开,介绍了缓存本地文件、用远程仓库内容强制覆盖本地仓库内容、查看日志、对比版本区别、解决冲突等操作,还包含相关名词解释。

1万+

被折叠的 条评论
为什么被折叠?



