git

Posted w123w

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了git相关的知识,希望对你有一定的参考价值。

出现这个问题的原因是git提交改动到缓存,要push的时候不会将本地所有的分支都push掉,所以出现这个问题。我们应该告诉git提交哪个分支。
这里有种特殊的情况是如果你是fork别人的仓库再clone到本地的话,即使git上只有一个主分支,他还是可能出现这个错误。那么我们就需要新建分支提交改动然后合并分支。

接下来先创建一个新分支提交改动

$ git branch newbranch
然后输入这条命令检查是否创建成功
$ git branch
这时输出
newbranch
* master
这样就创建成功了,前面的*代表的是当前你所在的工作分支。我们接下来就要切换工作分支。
$ git checkout newbranch
这样就切换完了,可以 $ git branch确认下。然后你要将你的改动提交到新的分支上。
$ git add .
$ git commit -a
此时可以 $ git status检查下提交情况。如果提交成功,我们接下来就要回主分支了,代码和之前一样。
$ git checkout master
然后我们要将新分支提交的改动合并到主分支上
$ git merge newbranch
合并分支可能产生冲突这是正常的,虽然我们这是新建的分支不会产生冲突,但还是在这里记录下。下面的代码可以查看产生冲突的文件,然后做对应的修改再提交一次就可以了。
$ git diff
我们的问题就解决了,接下来就可以push代码了。
$ git push -u origin master
新建分支的朋友别忘了删除这个分支
$ git branch -D newbranch
如果想保留分支只是想删除已经合并的部分只要把大写的D改成小写的d就行了


1、移除
git remote rm origin
2、再次连接
git remote add origin ‘地址’


 


 

 

$ git remote add origin git@47.105.95.107:chao123/wangchao.git

changer@DESKTOP-2S5TE8V MINGW64 ~/Desktop/新建文件夹 (master)
$ git push -u origin master
Everything up-to-date
Branch ‘master‘ set up to track remote branch ‘master‘ from ‘origin‘.

changer@DESKTOP-2S5TE8V MINGW64 ~/Desktop/新建文件夹 (master)
$ git branch -a
* master
remotes/origin/master
remotes/prigin/div

changer@DESKTOP-2S5TE8V MINGW64 ~/Desktop/新建文件夹 (master)
$ git remove -v
git: ‘remove‘ is not a git command. See ‘git --help‘.

The most similar command is
remote

changer@DESKTOP-2S5TE8V MINGW64 ~/Desktop/新建文件夹 (master)
$ git remote -v
origin git@47.105.95.107:chao123/wangchao.git (fetch)
origin git@47.105.95.107:chao123/wangchao.git (push)
prigin git@47.105.95.107:chao123/wangchao.git (fetch)
prigin git@47.105.95.107:chao123/wangchao.git (push)

changer@DESKTOP-2S5TE8V MINGW64 ~/Desktop/新建文件夹 (master)
$ git push -u origin master
Everything up-to-date
Branch ‘master‘ set up to track remote branch ‘master‘ from ‘origin‘.

changer@DESKTOP-2S5TE8V MINGW64 ~/Desktop/新建文件夹 (master)
$ git push -f origin master
Everything up-to-date

changer@DESKTOP-2S5TE8V MINGW64 ~/Desktop/新建文件夹 (master)
$ git remote rm origin

changer@DESKTOP-2S5TE8V MINGW64 ~/Desktop/新建文件夹 (master)
$ git remote rm pritin
fatal: No such remote: ‘pritin‘

changer@DESKTOP-2S5TE8V MINGW64 ~/Desktop/新建文件夹 (master)
$ git remote -a
error: unknown switch `a‘
usage: git remote [-v | --verbose]
or: git remote add [-t <branch>] [-m <master>] [-f] [--tags | --no-tags] [--mirror=<fetch|push>] <name> <url>
or: git remote rename <old> <new>
or: git remote remove <name>
or: git remote set-head <name> (-a | --auto | -d | --delete | <branch>)
or: git remote [-v | --verbose] show [-n] <name>
or: git remote prune [-n | --dry-run] <name>
or: git remote [-v | --verbose] update [-p | --prune] [(<group> | <remote>)...]
or: git remote set-branches [--add] <name> <branch>...
or: git remote get-url [--push] [--all] <name>
or: git remote set-url [--push] <name> <newurl> [<oldurl>]
or: git remote set-url --add <name> <newurl>
or: git remote set-url --delete <name> <url>

-v, --verbose be verbose; must be placed before a subcommand


changer@DESKTOP-2S5TE8V MINGW64 ~/Desktop/新建文件夹 (master)
$ git remote -v
prigin git@47.105.95.107:chao123/wangchao.git (fetch)
prigin git@47.105.95.107:chao123/wangchao.git (push)

changer@DESKTOP-2S5TE8V MINGW64 ~/Desktop/新建文件夹 (master)
$ git remote rm prigin

changer@DESKTOP-2S5TE8V MINGW64 ~/Desktop/新建文件夹 (master)
$ git remote add origin git@47.105.95.107:chao123/wangchao.git

changer@DESKTOP-2S5TE8V MINGW64 ~/Desktop/新建文件夹 (master)
$ git pull origin master
From 47.105.95.107:chao123/wangchao
* branch master -> FETCH_HEAD
* [new branch] master -> origin/master
Already up to date.

changer@DESKTOP-2S5TE8V MINGW64 ~/Desktop/新建文件夹 (master)
$ git push -u origin master
Everything up-to-date
Branch ‘master‘ set up to track remote branch ‘master‘ from ‘origin‘.

changer@DESKTOP-2S5TE8V MINGW64 ~/Desktop/新建文件夹 (master)
$ git remote rm prigin
fatal: No such remote: ‘prigin‘

changer@DESKTOP-2S5TE8V MINGW64 ~/Desktop/新建文件夹 (master)
$ git remote rm origin

changer@DESKTOP-2S5TE8V MINGW64 ~/Desktop/新建文件夹 (master)
$ git remote add origin git@47.105.95.107:chao123/wangchao.git

changer@DESKTOP-2S5TE8V MINGW64 ~/Desktop/新建文件夹 (master)
$ git remote -v
origin git@47.105.95.107:chao123/wangchao.git (fetch)
origin git@47.105.95.107:chao123/wangchao.git (push)

changer@DESKTOP-2S5TE8V MINGW64 ~/Desktop/新建文件夹 (master)
$ git push origin master
Everything up-to-date

changer@DESKTOP-2S5TE8V MINGW64 ~/Desktop/新建文件夹 (master)
$ git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: 1.0.0

Untracked files:
(use "git add <file>..." to include in what will be committed)
1.0.1.txt

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

changer@DESKTOP-2S5TE8V MINGW64 ~/Desktop/新建文件夹 (master)
$ git commit
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: 1.0.0

Untracked files:
(use "git add <file>..." to include in what will be committed)
1.0.1.txt

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

changer@DESKTOP-2S5TE8V MINGW64 ~/Desktop/新建文件夹 (master)
$ git branch
* master

changer@DESKTOP-2S5TE8V MINGW64 ~/Desktop/新建文件夹 (master)
$ git branch newbranch

changer@DESKTOP-2S5TE8V MINGW64 ~/Desktop/新建文件夹 (master)
$ git branch
* master
newbranch

changer@DESKTOP-2S5TE8V MINGW64 ~/Desktop/新建文件夹 (master)
$ git checkout newbranch
Switched to branch ‘newbranch‘
M 1.0.0

changer@DESKTOP-2S5TE8V MINGW64 ~/Desktop/新建文件夹 (newbranch)
$ git add
Nothing specified, nothing added.
hint: Maybe you wanted to say ‘git add .‘?
hint: Turn this message off by running
hint: "git config advice.addEmptyPathspec false"

changer@DESKTOP-2S5TE8V MINGW64 ~/Desktop/新建文件夹 (newbranch)
$ git commit -a
Aborting commit due to empty commit message.

changer@DESKTOP-2S5TE8V MINGW64 ~/Desktop/新建文件夹 (newbranch)
$ git status
On branch newbranch
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: 1.0.0

Untracked files:
(use "git add <file>..." to include in what will be committed)
1.0.1.txt

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

changer@DESKTOP-2S5TE8V MINGW64 ~/Desktop/新建文件夹 (newbranch)
$ git add
Nothing specified, nothing added.
hint: Maybe you wanted to say ‘git add .‘?
hint: Turn this message off by running
hint: "git config advice.addEmptyPathspec false"

changer@DESKTOP-2S5TE8V MINGW64 ~/Desktop/新建文件夹 (newbranch)
$ git add .

changer@DESKTOP-2S5TE8V MINGW64 ~/Desktop/新建文件夹 (newbranch)
$ git commit -m "这是newbranch的修改提交"
[newbranch c55aded] 这是newbranch的修改提交
2 files changed, 6 insertions(+), 1 deletion(-)
create mode 100644 1.0.1.txt

changer@DESKTOP-2S5TE8V MINGW64 ~/Desktop/新建文件夹 (newbranch)
$ Git status
On branch newbranch
nothing to commit, working tree clean

changer@DESKTOP-2S5TE8V MINGW64 ~/Desktop/新建文件夹 (newbranch)
$ git checkout master
Switched to branch ‘master‘

changer@DESKTOP-2S5TE8V MINGW64 ~/Desktop/新建文件夹 (master)
$ git merge newbranch
Updating 72e55a0..c55aded
Fast-forward
1.0.0 | 7 ++++++-
1.0.1.txt | 0
2 files changed, 6 insertions(+), 1 deletion(-)
create mode 100644 1.0.1.txt

changer@DESKTOP-2S5TE8V MINGW64 ~/Desktop/新建文件夹 (master)
$ git diff

changer@DESKTOP-2S5TE8V MINGW64 ~/Desktop/新建文件夹 (master)
$ git push -u origin master
Enumerating objects: 6, done.
Counting objects: 100% (6/6), done.
Delta compression using up to 4 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (4/4), 356 bytes | 89.00 KiB/s, done.
Total 4 (delta 0), reused 0 (delta 0), pack-reused 0
To 47.105.95.107:chao123/wangchao.git
72e55a0..c55aded master -> master
Branch ‘master‘ set up to track remote branch ‘master‘ from ‘origin‘.

 
































































































































































以上是关于git的主要内容,如果未能解决你的问题,请参考以下文章

Git 学习路线

从0到1带你掌握git(一分钟掌握git)--git如何下载?git如何使用?git是什么?git怎么获取文件?

Git认识与使用 Git

Git认识与使用 Git

Git认识与使用 Git

Git认识与使用 Git