git 操作 (二)

配置远程仓库

git remote add origin https://github.com/Jay778/Night.git

修改远程仓库

D:\message_write_card>git remote -v
origin  ssh://qiankunpingtai@39.155.163.206:123456/message_write_card (fetch)
origin  ssh://qiankunpingtai@39.155.163.206:123456/message_write_card (push)

D:\message_write_card>git remote set-url origin ssh://qiankunpingtai@gerrit.qiankunpingtai.com:123456/message_write_card

D:\message_write_card>git pull --rebase
The authenticity of host '[gerrit.qiankunpingtai.com]:123456 ([192.168.204.168]:123456)' can't be established.
RSA key fingerprint is SHA256:eurdsfjsdiFJD	JDFI.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '[gerrit.qiankunpingtai.com]:123456,[192.168.204.168]:123456' (RSA) to the list of known hosts.
Current branch master is up to date.

D:\writecardtool>git remote set-url origin ssh://qiankunpingtai@39.155.163.206:123456/writecardtool

fatal: No such remote 'origin'

D:\writecardtool>git remote add origin ssh://qiankunpingtai@39.155.163.206:123456/writecardtool

修改本地分支跟踪远程分支

git branch --set-upstream-to= 远程分支 本地分支

D:\writecardtool>git branch -vv
  dev    e3e7f20 dev init
* master 4934b6b 服务器ip地址变更
D:\writecardtool>git branch --set-upstream-to=master dev
Branch 'dev' set up to track local branch 'master'.
D:\writecardtool>git branch -vv
  dev    e3e7f20 [master: ahead 1, behind 76] dev init
* master 4934b6b 服务器ip地址变更

D:\writecardtool>git branch --set-upstream-to=origin/master master
Branch 'master' set up to track remote branch 'master' from 'origin'.

D:\writecardtool>git branch -vv
  dev    e3e7f20 [master: ahead 1, behind 76] dev init
* master 4934b6b [origin/master: ahead 3, behind 7] 服务器ip地址变更

dev 分支和主分支合并

dev 分支提交文件

git  add .
git  commit -m '提交的备注信息'
git  push -u origin dev

切换到 master 分支

git  checkout master

更新 master 分支

git pull origin master

将 dev 分支的文件更新到 master 分支

git  merge dev

查看 mater 分支状态

git status

存在冲突文件,解决冲突

提交 master 分支文件

git  add .
git  commit -m '提交的备注信息'
git  push -u origin master

dev 部分文件提交到 master

切换到 master 分支

git  checkout master

更新 master 分支

git pull origin master

检出要合并的文件

git checkout --patch 分支名称 要合并的文件路径

git checkout --patch dev src/models/test.java

查看 mater 分支状态

git status

存在冲突文件,解决冲突

提交 master 分支文件

git  add .
git  commit -m '提交的备注信息'
git  push -u origin master

git stash

-q|--quiet 静默模式
-p|--patch 以 patch 方式 push stash
-k|--[no-]keep-index 保留 index 序号
-u|--include-untracked untracked 状态的文件也会被 push
-a|--all untracked 和 ignored 的文件也会被 push
-m|--message 输出 stash 信息
-- [] 针对特定的路径 push

执行存储时,添加备注(git stash save "备注")

D:\chipsystem_develop\06代码\02后端>git stash save "测试"
Saved working directory and index state On dev: 测试

D:\chipsystem_develop\06代码\02后端>git stash list
stash@{0}: On dev: 测试

查看 stash 了哪些存储(git stash list)

D:\chipsystem_develop\06代码\02后端>git stash list
stash@{0}: On dev: 测试
stash@{1}: WIP on dev: a0d4013 添加码号是否已写卡功能
stash@{2}: WIP on dev: a0d4013 添加码号是否已写卡功能

显示做了哪些改动(git stash show)

默认 show 第一个存储, 如果要显示其他存贮,后面加 stash@{$num},比如第二个 git stash show stash@{1}

D:\chipsystem_develop\06代码\02后端>git stash show
 .../src/main/resources/config/config.properties"                         | 1 +
 1 file changed, 1 insertion(+)

显示存储改动的详情(git stash show -p)

默认显示第一个存储的改动,如果想显示其他存储,命令:git stash show stash@{$num} -p ,比如第二个:git stash show stash@{1} -p

D:\chipsystem_develop\06代码\02后端>git stash show -p
diff --git "a/06\344\273\243\347\240\201/02\345\220\216\347\253\257/src/main/resources/config/config.properties" "b/06\344\273\243\347\240\201/02\345\
220\216\347\253\257/src/main/resources/config/config.properties"
index 1a3cab2..664e577 100644
--- "a/06\344\273\243\347\240\201/02\345\220\216\347\253\257/src/main/resources/config/config.properties"
+++ "b/06\344\273\243\347\240\201/02\345\220\216\347\253\257/src/main/resources/config/config.properties"
@@ -26,6 +26,7 @@ default.jdbc.driverClassName = com.mysql.jdbc.Driver
 default.jdbc.maximumPoolSize=20
 default.jdbc.minIdle=5

+
 ######home  for  本机
 #local.datasource.jdbcUrl = jdbc:mysql://127.0.0.1:3306/chipsystem?useUnicode=true&characterEncoding=UTF-8&useSSL=false&allowMultiQueries=true
 #local.datasource.username = chipuser

应用某个存储, 但不会把存储从存储列表中删除(git stash apply)

默认使用第一个存储, 即 stash@{0},如果要使用其他个,git stash apply stash@{$num} , 比如第二个:git stash apply stash@{1}

D:\chipsystem_develop\06代码\02后端>git stash apply
On branch dev
Your branch is ahead of 'origin/dev' by 1 commit.
  (use "git push" to publish your local commits)

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:   src/main/resources/config/config.properties

no changes added to commit (use "git add" and/or "git commit -a")

恢复之前缓存的到工作目录,将缓存堆栈中的对应 stash 删除(git stash pop)

默认为第一个 stash, 即 stash@{0},如果要应用并删除其他 stash,命令:git stash pop stash@{$num} ,比如应用并删除第二个:git stash pop stash@{1}

D:\chipsystem_develop\06代码\02后端>git stash list
stash@{0}: WIP on dev: a0d4013 添加码号是否已写卡功能
stash@{1}: On dev: 测试
stash@{2}: WIP on dev: a0d4013 添加码号是否已写卡功能
stash@{3}: WIP on dev: a0d4013 添加码号是否已写卡功能

D:\chipsystem_develop\06代码\02后端>git stash pop
On branch dev
Your branch is ahead of 'origin/dev' by 1 commit.
  (use "git push" to publish your local commits)

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:   src/main/resources/config/config.properties

no changes added to commit (use "git add" and/or "git commit -a")
Dropped refs/stash@{0} (f0ced9c591dab248ac739232632c31a4ee660362)

D:\chipsystem_develop\06代码\02后端>git stash list
stash@{0}: On dev: 测试
stash@{1}: WIP on dev: a0d4013 添加码号是否已写卡功能
stash@{2}: WIP on dev: a0d4013 添加码号是否已写卡功能

丢弃 stash,并从列表中删除这个存储(git stash drop stash@{$num})

丢弃 stash@{$num} 存储,从列表中删除这个存储

 D:\chipsystem_develop\06代码\02后端>git stash list
stash@{0}: On dev: 测试
stash@{1}: WIP on dev: a0d4013 添加码号是否已写卡功能
stash@{2}: WIP on dev: a0d4013 添加码号是否已写卡功能

D:\chipsystem_develop\06代码\02后端>git stash drop stash@{0}
Dropped stash@{0} (5d51714a41397740bc66d6a127174bf98356988b)

D:\chipsystem_develop\06代码\02后端>git stash list
stash@{0}: WIP on dev: a0d4013 添加码号是否已写卡功能
stash@{1}: WIP on dev: a0d4013 添加码号是否已写卡功能

删除所有缓存的 stash(git stash clear)


D:\chipsystem_develop\06代码\02后端>git stash list
stash@{0}: WIP on dev: a0d4013 添加码号是否已写卡功能
stash@{1}: WIP on dev: a0d4013 添加码号是否已写卡功能

D:\chipsystem_develop\06代码\02后端>git stash clear

D:\chipsystem_develop\06代码\02后端>git stash list

上一篇 git 操作 (一)