git常用命令

1.简历github仓库https://github.com/fulq1234/a.git
2.建立本地仓库。我在本地新建一个文件夹gitgit,打开文件夹,右键选择git bash here

git init

3.在gitgit下面新建一个文件夹adddd,

git add .

4. git仓库迁移,git remote更改源

  • git remote                                    #不带参数,列出已经存在的远程分支
  • git remote -v                                 #(-v是–verbose 的简写,取首字母)列出详细信息,在每一个名字后面列出其远程url
  • git remote add [shortname] [url]              #添加远程仓库
  • git remote rm [shorname]                #删除git
$ git remote -v

$ git remote add origin https://github.com/fulq1234/a.git

$ git remote -v
origin  https://github.com/fulq1234/a.git (fetch)
origin  https://github.com/fulq1234/a.git (push)

$ git remote add origin2 https://github.com/fulq1234/a.git

$ git remote -v
origin  https://github.com/fulq1234/a.git (fetch)
origin  https://github.com/fulq1234/a.git (push)
origin2 https://github.com/fulq1234/a.git (fetch)
origin2 https://github.com/fulq1234/a.git (push)

$ git remote add origin2 https://github.com/fulq1234/a.git
fatal: remote origin2 already exists.

$ git remote rm origin2

$ git remote add origin2 https://github.com/fulq1234/a.git

$ git remote -v
origin  https://github.com/fulq1234/a.git (fetch)
origin  https://github.com/fulq1234/a.git (push)
origin2 https://github.com/fulq1234/a.git (fetch)
origin2 https://github.com/fulq1234/a.git (push)


5. 拉取远程仓库的代码。
git pull origin master
6.提交本地代码
git add .
git commit -m ""
git push origin master
7.怎么解决冲突。如果远程的一个文件改变了,本地的也改变了。那么提交代码会冲突

$ git add .

$ git commit -m "bbb"
[master 908e9a5] bbb
 1 file changed, 2 insertions(+), 1 deletion(-)

$ git push origin master
To https://github.com/fulq1234/a.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://github.com/fulq1234/a.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.

方法1:
更新成最新代码
git pull origin master
再看冲突的那个文件,本地代码和远程仓库的代码都有。需要修改后提交。

方法2:git stash
$ git stash save "1"
Saved working directory and index state On master: 1

$ git stash list
stash@{0}: On master: 1

$ git stash show
 a.txt | 1 +
 1 file changed, 1 insertion(+)

$ git pull origin master
remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
From https://github.com/fulq1234/a
 * branch            master     -> FETCH_HEAD
   f01172d..55fa00a  master     -> origin/master
Updating f01172d..55fa00a
Fast-forward
 a.txt | 1 +
 1 file changed, 1 insertion(+)

再看冲突的那个文件,本地代码和远程仓库的代码都有。需要修改后提交。

$ git stash pop
Auto-merging a.txt
CONFLICT (content): Merge conflict in a.txt

方法3:把冲突文件新建分支,把文件再合并,删除新建的那个分支

8.多个版本切换
git log 查看历史记录
--hard当前版本,--hard^上一个版本。
git reset --hard HEAD

版本切换:
git reset --hard c17177259e63a6f964b27be0a0b1ee6ad4882abd

9.分支
git branch iss53    #建一个分支名字叫iss53
git checkout iss53    #版本切换到分支iss53上面
如果想把master合并到iss53上。
第一步,切换到master 。
git checkout master
第二步,合并iss53
git merge iss53
10.删除分支
git branch -d hotfix        #删除分支hotfix

11.查看当前分支,删除远程分支

F:\workspace\project>git branch -a
* dev
  dev-20200309
  master
  remotes/origin/HEAD -> origin/master
  remotes/origin/dev
  remotes/origin/dev-20200226
  remotes/origin/dev-20200309
  remotes/origin/dev-20200309-<E7><96><AB><E6><83><85>
  remotes/origin/dev-PL<E7><96><AB>
  remotes/origin/master
  remotes/origin/rostering
F:\workspace\project>git push origin --delete dev-20200226
To http://git.hldev.com/hlhlo/zillion-wfm.git
 - [deleted]           dev-20200226

F:\workspace\project>git branch -a
* dev
  dev-20200309
  master
  remotes/origin/HEAD -> origin/master
  remotes/origin/dev
  remotes/origin/dev-20200309
  remotes/origin/dev-20200309-<E7><96><AB><E6><83><85>
  remotes/origin/dev-PL<E7><96><AB>
  remotes/origin/master
  remotes/origin/rostering
F:\workspace\project>git push origin --delete dev-20200309-疫情
To http://git.hldev.com/hlhlo/zillion-wfm.git
 - [deleted]           dev-20200309-疫情

F:\workspace\project>git branch -a
* dev
  dev-20200309
  master
  remotes/origin/HEAD -> origin/master
  remotes/origin/dev
  remotes/origin/dev-20200309
  remotes/origin/dev-PL<E7><96><AB>
  remotes/origin/master
  remotes/origin/rostering
F:\workspace\project>git push origin --delete dev-20200309
To http://git.hldev.com/hlhlo/zillion-wfm.git
 - [deleted]           dev-20200309

F:\workspace\project>git branch -a
* dev
  dev-20200309
  master
  remotes/origin/HEAD -> origin/master
  remotes/origin/dev
  remotes/origin/dev-PL<E7><96><AB>
  remotes/origin/master
  remotes/origin/rostering

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值