git学习
-
git init
git init
创建本地仓库
-
git add
add git.txt git.md
将文件加入暂存区
-
git commit
git commit -m 'feat:learn git'
实际上就是把暂存区的所有内容提交到当前分支。
///before add/ PS D:\learn\git> git status On branch 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) modified: git.md no changes added to commit (use "git add" and/or "git commit -a") //after add before commit/ PS D:\learn\git> git status On branch master Changes to be committed: (use "git reset HEAD <file>..." to unstage) modified: git.md //after commit// PS D:\learn\git> git status On branch master nothing to commit, working tree clean
-
git log
git log//打印git提交信息 git log --pretty=oneline//在一行显示,比较好看
-
git reset
git reset --hard HEAD^//回退到上一个版本 git reset --hard b4dc2//回到制定版本,b4dc2回退版本之前的版本
-
git reflog
git reflog
用来记录你的每一次命令
-
git diff HEAD – git.txt
git diff HEAD -- git.txt//命令可以查看工作区和版本库里面最新版本的区别
diff --git a/git.txt b/git.txt index 87451e7…1b2a993 100644 — a/git.txt +++ b/git.txt @@ -1 +1,2 @@ -test 3 \ No newline at end of file +test 3 +test 555 \ No newline at end of file
-
git checkout
git checkout -- git.txt
用于删除还未add的修改
git reset HEAD git.txt
git reset HEAD 文件,将暂存区中的内容删除,然后再checkout,就把这次更改删掉
-
git remote
git remote//查看远程仓库信息 git remote -v//查看详细信息 /** origin https://github.com/Nortyr/learnGit.git (fetch) origin https://github.com/Nortyr/learnGit.git (push) 上面显示了可以抓取和推送的origin的地址。如果没有推送权限,就看不到push的地址。 */ git remote add origin https://github.com/Nortyr/learnGit.git git remote rm origin//删除原有关联
将本地代码和远程代码关联
-
git push
git push -u origin master//第一次 git push origin master//以后
将本地仓库推到线上仓库备份
-
git clone
git clone https://github.com/Nortyr/learnGitClone.git
从线上clone一个仓库
-
git checkout
git checkout -b dev//创建并指向dev分支 ///相当于 git branch dev git checkout dev//切换(指向)分支 git checkout -b dev origin/dev
-
git branch
git branch chen//创建chen分支 git branch//查看所有分支 git branch -d chen//删除chen分支 git branch --set-upstream-to=origin/<branch> dev//在本地创建和远程分支对应的分支,最好名称一致 git branch -vv//查看本地分支和远程分支关系 git branch -u origin/master//将当前分支跟踪origin/master
-
git merge
git merge dev//将dev分支合并到当前分支
-
git stash
git stash//未提交的东西会放到stash里面,add和仅保存的东西会暂存起来 当某项紧急任务完成后,回到当前分支 git stash pop//原先内容会出来,如果有改动,要合并冲突(git stash apply+git stash drop) git stash list//查看stash列表 git stash apply//恢复 git stash drop//删除git stash中的内容
//Git友情提醒,`feature-vulcan`分支还没有被合并,如果删除,将丢失掉修改,如果要强行删除,需要使用大写的`-D`参数。 git branch -D xxxxxx
-
git commit 时禁止将LF转换为CRLF
git config --global core.autocrlf false
- git pull
git pull origin master --allow-unrelated-histories 把两个不想关的仓库合并