利用Git 提交代码

Git

1.首先确定自己电脑里面是否安装了git,如果安装了会出现下面的信息

C:\Zto\sjjsc>git
usage: git [--version] [--help] [-C <path>] [-c <name>=<value>]
           [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
           [-p | --paginate | -P | --no-pager] [--no-replace-objects] [--bare]
           [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
           <command> [<args>]

These are common Git commands used in various situations:

start a working area (see also: git help tutorial)
   clone      Clone a repository into a new directory
   init       Create an empty Git repository or reinitialize an existing one

work on the current change (see also: git help everyday)
   add        Add file contents to the index
   mv         Move or rename a file, a directory, or a symlink
   reset      Reset current HEAD to the specified state
   rm         Remove files from the working tree and from the index

examine the history and state (see also: git help revisions)
   bisect     Use binary search to find the commit that introduced a bug
   grep       Print lines matching a pattern
   log        Show commit logs
   show       Show various types of objects
   status     Show the working tree status

grow, mark and tweak your common history
   branch     List, create, or delete branches
   checkout   Switch branches or restore working tree files
   commit     Record changes to the repository
   diff       Show changes between commits, commit and working tree, etc
   merge      Join two or more development histories together
   rebase     Reapply commits on top of another base tip
   tag        Create, list, delete or verify a tag object signed with GPG

collaborate (see also: git help workflows)
   fetch      Download objects and refs from another repository
   pull       Fetch from and integrate with another repository or a local branch
   push       Update remote refs along with associated objects

'git help -a' and 'git help -g' list available subcommands and some
concept guides. See 'git help <command>' or 'git help <concept>'
to read about a specific subcommand or concept.

如果没有,那么就先安装git,就去git官网上下载,安装,https://git-scm.com/downloads,安装成功后会,输入命令git --version,会出现安装的版本号。

C:\Zto\sjjsc>git --version
git version 2.18.0.windows.1

2.配置自己的个人信息,以后提交代码,就会出现提交人的信息等信息。

C:\Zto\sjjsc> git config --global user.name "你的名称"  
C:\Zto\sjjsc>git config --global user.email "你的邮箱" 

如果已经输入过了,但是忘记了自己的之前git的名称,可以用git config --list,查看自己信息。

3.下面我们就可以开始我们的代码了,首先进入你要将代码存放的目录,我的git的代码存放在我的Zto/sjjsc下面,所以我们定位到该目录下。cd  c:/Zto/sjjsc,然后git init,创建了一个空的本地仓库。

C:\Zto\sjjsc>cd c:/Zto/sjjsc

C:\Zto\sjjsc>git init
Reinitialized existing Git repository in C:/Zto/sjjsc/.git/

下面就是拉取远程的代码了。g'i

这时候就把远程的代码拉到本地的Zto/sjjsc文件下面了。

4.你拉取的代码,应该都有一个分支,默认master分支,但是具体是什么,看你git上,项目开始分配的分支是什么,我的是develop。你拉取代码的时候,最好切换下分支。
      git branch -a    //查看分支
      git checkout develop  //切换分支

如果你查看分支后,发现你的分支与git不同,那么请切换到与git上一致的分支上,此时我已经切换到develop分支上了
 

C:\Zto\sjjsc>git checkout develop
Already on 'develop'
Your branch is up to date with 'origin/develop'.

5.如果本地改了代码,想将代码提交到分支上去,执行个git status,他会显示你本地修改的文件。 modified后面就是你修改的文件名称

C:\Zto\sjjsc>git status
On branch develop
Your branch is up to date with 'origin/develop'.

You are currently rebasing branch 'develop' on 'b30681d'.
  (all conflicts fixed: run "git rebase --continue")

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/views/test.vue

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

6.’git add .' ,后面的'.',会将你上面modified后面所有的文件都提交到分支上,如果你部分修改的文件不想提交,那么将‘.'换成你要提交的文件名即可。然后git commit -m '提交时候的备注’
 

C:\Zto\sjjsc>git add .

C:\Zto\sjjsc>git commit -m '循环加key属性'
[develop 42e8635] '循环加key属性'
 1 file changed, 1 insertion(+), 1 deletion(-)

7.git push,将你更改的代码提交到远程上面去。一定要commit --> pull --> push
 

结语:后面遇到问题,会继续补充更新。

猜你喜欢

转载自blog.csdn.net/little_pig_bug/article/details/81163511