zoukankan      html  css  js  c++  java
  • git 命令

    Command line instructions
    Git global setup
    git config --global user.name "kaniel"
    git config --global user.email "kaniel520@foxmail.com"

    Create a new repository
    git clone git@gitlab.example.com:meikaxiu/Android.git
    cd Android

    touch README.md
    git add README.md
    git commit -m "add README"
    git push -u origin master

    Existing folder or Git repository
    cd existing_folder
    git init
    git remote add origin git@gitlab.example.com:meikaxiu/Android.git
    git add .
    git commit
    git push -u origin master




    Existing Git repository

    cd existing_repo
    git remote rename origin old-origin
    git remote add origin git@192.168.3.207:weiyun_projects/decode_video/GPU_GB28181.git
    git push -u origin --all
    git push -u origin --tags






    git init  在当前目录下面创建一个仓库
    git add xxx.txt 把文件提交到缓存区
        git add 命令使用文件或目录的路径作为参数;如果参数是目录的路径,该命令将递归地跟踪该目录下的所有文件。
        是个多功能命令:可以用它开始跟踪新文件,或者把已跟踪的文件放到暂存区,还能用于合并时把有冲突的文件标记为已解决状态等。
        将这个命令理解为“添加内容到下一次提交中”而不是“将一个文件添加到项目中”要更加合适。
        
    git add .(慎用,这个会把所有跟踪,未跟踪的文件全部提到暂存区)


    git add -u 提交所有跟踪的文件的变化到暂存区
        
    git add -f xxx.txt    强制提交某个被禁止提交的文件
        
    git add -i [<path>]命令查看<path>中被所有修改过或已删除文件但没有提交的文件

    git diff --staged 查看已暂存的将要添加到下次提交里的内容

    git rm --cached README 保留本地文件,把文件从 Git 仓库中删除(亦即从暂存区域移除)

    git checkout -- file 恢复文件到刚提交到暂存区域的状态(也就是删除,文件提交到暂存区域后,的更改)

    git reset HEAD <file> 让文件退出暂存区
        
    git commit -m "提示文字"

    git config --list 查看配置的资料




    $ git commit -m 'initial commit'
    $ git add forgotten_file
    $ git commit --amend

    提交到远端:git push --no-thin origin HEAD:refs/for/master
    --no-thin 把差异的部分传到远端


    最终只有一个提交'initial commit' ,最后追加了forgotten_file 主要靠git commit --amend 命令





    git status 查看当前仓库状态
        1.$ git status
        On branch master
        Untracked files:
          (use "git add <file>..." to include in what will be committed)

            README
        未跟踪的文件意味着 Git 在之前的快照(提交)中没有这些文件;Git 不会自动将之纳入跟踪范围,除非你明明白白地告诉它“我需要跟踪该文件”, 这样的处理让你不必担心将生成的二进制文件或其它不想被跟踪的文件包含进来    
        
        2.git status
        On branch master
        Changes to be committed:
        (use "git reset HEAD <file>..." to unstage)

        new file:   README
        只要在 Changes to be committed 这行下面的,就说明是已暂存状态。 如果此时提交,那么该文件此时此刻的版本将被留存在历史记录中
        
        3.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:   CONTRIBUTING.md
        出现在 Changes not staged for commit 这行下面,说明已跟踪文件的内容发生了变化,但还没有放到暂存区,
        要暂存这次更新,需要运行 git add 命令
        
        4.$ git status
        On branch master
        Changes to be committed:
          (use "git reset HEAD <file>..." to unstage)

            new file:   README
            modified:   CONTRIBUTING.md

        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:   CONTRIBUTING.md
             现在 CONTRIBUTING.md 文件同时出现在暂存区和非暂存区。 这怎么可能呢? 好吧,实际上 Git 只不过暂存了你运行 git add 命令时的版本, 如果你现在提交,CONTRIBUTING.md 的版本是你最后一次运行 git add 命令时的那个版本,而不是你运行 git commit 时,在工作目录中的当前版本。 所以,运行了 git add 之后又作了修订的文件,需要重新运行 git add 把最新版本重新暂存起来
            
        5.$ git status -s
         M README
        MM Rakefile
        A  lib/git.rb
        M  lib/simplegit.rb
        ?? LICENSE.txt
        新添加的未跟踪文件前面有 ?? 标记,
        新添加到暂存区中的文件前面有 A 标记,
        修改过的文件前面有 M 标记。
        你可能注意到了 M 有两个可以出现的位置,出现在右边的 M 表示该文件被修改了但是还没放入暂存区,出现在靠左边的 M 表示该文件被修改了并放入了暂存区。
        例如,上面的状态报告显示:
        README 文件在工作区被修改了但是还没有将修改后的文件放入暂存区,
        lib/simplegit.rb 文件被修改了并将修改后的文件放入了暂存区。
        而 Rakefile 在工作区被修改并提交到暂存区后又在工作区中被修改了,所以在暂存区和工作区都有该文件被修改了的记录。
        
        
        
    .gitignore
        $ cat .gitignore
        *.[oa]
        *~
        第一行告诉 Git 忽略所有以 .o 或 .a 结尾的文件。一般这类对象文件和存档文件都是编译过程中出现的。 第二行告诉 Git 忽略所有以波浪符(~)结尾的文件,许多文本编辑软件(比如 Emacs)都用这样的文件名保存副本。 此外,你可能还需要忽略 log,tmp 或者 pid 目录,以及自动生成的文档等等。 要养成一开始就设置好 .gitignore 文件的习惯,以免将来误提交这类无用的文件。
        
        
    git diff XXX 查看文件哪些被修改了(无文件就是当前目录的不同)
    git diff --staged 查看已暂存的将要添加到下次提交里的内容(就是已经 git  add 的内容)
    git diff --cached 显示暂存区与历史版本库的差异
    git diff --stat 查看摘要
    git diff SHA1 SHA2 比较两个历史版本之间的差异

     

    执行 $ git diff <filename> 命令,查看filename文件,对比本地master版本,当前修改的差异和修改add的差异。

    执行 $ git diff HEAD -- <filename>  查看filename文件,对比本地master版本,当前修改的差异和修改后add的差异。

    执行 $ git diff HEAD^ -- <filename> 查看filename文件,对比本地master上一个版本,当前修改的差异和修改add的差异和master的差异

    执行 $ git diff HEAD^^ -- <filename> 同理


        


    git show [commit_id]      查看某次历史提交信息的完整信息

    git show master 查看master分支最新一次提交的完整信息

    git show HEAD 查看HEAD标签当前指向的提交的完整信息


    git log 查看最近提交的日志

    一个常用的选项是 -p,用来显示每次提交的内容差异。
     你也可以加上 -2 来仅显示最近两次提交:
    比如说,如果你想看到每次提交的简略的统计信息,你可以使用 --stat 选项
    git log --pretty=oneline

    $ git log --pretty=format:"%h - %an, %ar : %s"
    ca82a6d - Scott Chacon, 6 years ago : changed the version number
    085bb3b - Scott Chacon, 6 years ago : removed unnecessary test
    --since, --after    

    仅显示指定时间之后的提交。
    --until, --before
    仅显示指定时间之前的提交。
    --author
    仅显示指定作者相关的提交。
    --committer
    仅显示指定提交者相关的提交。

    git log --oneline --decorate    
        你可以简单地使用 git log 命令查看各个分支当前所指的对象。 提供这一功能的参数是 --decorate。
        $ git log --oneline --decorate
        f30ab (HEAD, master, testing) add feature #32 - ability to add new
        34ac2 fixed bug #1328 - stack overflow under certain conditions
        98ca9 initial commit of my project
        正如你所见,当前 “master” 和 “testing” 分支均指向校验和以 f30ab 开头的提交对象。


    git log –p输出每一个commit之间的差异信息
    git log -p -2        
        我们常用 -p 选项展开显示每次提交的内容差异,用 -2 则仅显示最近的两次更新:
        $ git log -p -2    
        
    git log --oneline --decorate --graph --all
        它会输出你的提交历史、各个分支的指向以及项目的分支分叉情况。
        
    git log --stat     
        在做代码审查,或者要快速浏览其他协作者提交的更新都作了哪些改动时,就可以用这个选项。此外,还有许多摘要选项可以用,比如 --stat,仅显示简要的增改行数统计:

    $ git log v1.0..        查询从v1.0以后的提交历史记录(不包含v1.0)
    $ git log test..master 查询master分支中的提交记录但不包含test分支记录
    $ git log master..test 查询test分支中的提交记录但不办含master分支记录
    $ git log master...test 查询master或test分支中的提交记录。
    $ git log test --not master  屏蔽master分支

    git log --mergs 查看所有合并过的提交历史记录

    git log --no-merges     查看所有未被合并过的提交信息

    git log --author=someonet       查询指定作者的提交记录

    $ git log --author=gbyukg





    git reset --hard HEAD^ 回退到上一个版本
    上一个版本就是HEAD^,上上一个版本就是HEAD^^,
    当然往上100个版本写100个^比较容易数不过来,所以写成HEAD~100

    git reset --hard 3628164 3628164是commit id,移动指针到指定的commit

    如CONTRIBUTING.md被错误的添加到了暂存区
        $ git add *
        $ git status
        On branch master
        Changes to be committed:
          (use "git reset HEAD <file>..." to unstage)

            renamed:    README.md -> README
            modified:   CONTRIBUTING.md
            
        $ git reset HEAD CONTRIBUTING.md
        Unstaged changes after reset:
        M    CONTRIBUTING.md
        $ git status
        On branch master
        Changes to be committed:
          (use "git reset HEAD <file>..." to unstage)

            renamed:    README.md -> README

        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:   CONTRIBUTING.md    
            
            
        你该如何方便地撤消修改 (还未add到暂存区域)- 将它还原成上次提交时的样子    
        git checkout -- CONTRIBUTING.md
        

    git commit -m "append GPL"
    [master 3628164] append GPL
        请记住,提交时记录的是放在暂存区域的快照。 任何还未暂存的仍然保持已修改状态,可以在下次提交时纳入版本管理。 每一次运行提交操作,都是对你项目作一次快照,以后可以回到这个状态,或者进行比较。
        Git 提供了一个跳过使用暂存区域的方式, 只要在提交的时候,给 git commit 加上 -a 选项,Git 就会自动把所有已经跟踪过的文件暂存起来一并提交,从而跳过 git add 步骤
        
    git reflog 查看你的每一次命令

    命令git checkout -- readme.txt意思就是,把readme.txt文件在工作区的修改全部撤销,这里有两种情况:

    一种是readme.txt自修改后还没有被放到暂存区,现在,撤销修改就回到和版本库一模一样的状态;

    一种是readme.txt已经添加到暂存区后,又作了修改,现在,撤销修改就回到添加到暂存区后的状态。

    删除未暂存的文件
    1. rm PROJECTS.md
    2.git rm PROJECTS.md

    删除已经提交到暂存区的文件
    1. rm PROJECTS.md
    2.git rm -f PROJECTS.md

    保留本地文件,把文件从 Git 仓库中删除(亦即从暂存区域移除)
    1.$ git rm --cached README


    $ git rm log/*.log :此命令删除 log/ 目录下扩展名为 .log 的所有文件
    $ git rm *~ 该命令为删除以 ~ 结尾的所有文件。

    git mv:重命名
     $ git mv file_from file_to
     
     
     
    $ git commit -m 'initial commit'
    $ git add forgotten_file
    $ git commit --amend
    最终你只会有一个提交 - 第二次提交将代替第一次提交的结果。





    远程仓库创建

    本地Git仓库和GitHub仓库之间的传输是通过SSH加密
    ssh-keygen -t rsa -C "youremail@example.com"
    用户主目录里找到.ssh目录,里面有id_rsa和id_rsa.pub两个文件
    _rsa是私钥,不能泄露出去,id_rsa.pub是公钥,可以放心地告诉任何人


    git@git.bkaqiu.com:meikaxiu/ui.git


    F:yyreader>git branch -a  //查看所有分支
    * master
      remotes/origin/CGmaybe_10
      remotes/origin/master

    F:yyreader>git checkout -b mujunling  //创建并切换的mujunling分支
    M       .gradle/2.10/taskArtifacts/cache.properties.lock
    M       .gradle/2.10/taskArtifacts/fileHashes.bin
    M       .gradle/2.10/taskArtifacts/fileSnapshots.bin
    M       .gradle/2.10/taskArtifacts/outputFileStates.bin
    M       .gradle/2.10/taskArtifacts/taskArtifacts.bin
    M       .idea/misc.xml
    M       .idea/workspace.xml
    M       slidingmenu_library/build/intermediates/bundles/debug/classes.jar
    M       slidingmenu_library/build/intermediates/bundles/release/classes.jar
    M       slidingmenu_library/build/intermediates/res/resources-debug-androidTest.ap_
    M       slidingmenu_library/build/outputs/aar/slidingmenu_library-debug.aar
    M       slidingmenu_library/build/outputs/aar/slidingmenu_library-release.aar
    M       yyReader/build/intermediates/blame/res/debug/single/anim.json
    M       yyReader/build/intermediates/blame/res/debug/single/drawable-hdpi-v4.json
    M       yyReader/build/intermediates/blame/res/debug/single/drawable-xxhdpi-v4.json
    M       yyReader/build/intermediates/blame/res/debug/single/drawable.json
    M       yyReader/build/intermediates/exploded-aar/yyreader/slidingmenu_library/unspecified/jars/classes.jar
    M       yyReader/build/intermediates/res/resources-debug-androidTest.ap_
    M       yyReader/build/intermediates/res/resources-debug.ap_
    M       yyReader/yyReader.iml
    Switched to a new branch 'mujunling'

    F:yyreader>git branch -a
      master
    * mujunling
      remotes/origin/CGmaybe_10
      remotes/origin/master

    F:yyreader>git push origin mujunling  //推送当前本地分支到远端
    Total 0 (delta 0), reused 0 (delta 0)
    To https://git.coding.net/balder_m/reader.git
     * [new branch]      mujunling -> mujunling

    F:yyreader>git branch -a
      master
    * mujunling
      remotes/origin/CGmaybe_10
      remotes/origin/master
      remotes/origin/mujunling

    F:yyreader>git branch
      master
    * mujunling


    git clone https://github.com/libgit2/libgit2
        1.当前目录下创建一个名为 “libgit2” 的目录
        2.并在这个目录下初始化一个 .git 文件夹,从远程仓库拉取下所有数据放入 .git 文件夹,然后从中读取最新版本的文件的拷贝
    $ git clone https://github.com/libgit2/libgit2 mylibgit
        1.当前目录下创建一个名为 “mylibgit” 的目录
        2.并在这个目录下初始化一个 .git 文件夹,从远程仓库拉取下所有数据放入 .git 文件夹,然后从中读取最新版本的文件的拷贝


    git remote
         它会列出你指定的每一个远程服务器的简写。
         如果你已经克隆了自己的仓库,那么至少应该能看到 origin - 这是 Git 给你克隆的仓库服务器的默认名字
     
    git remote -v 列出所有的git
        origin    https://github.com/schacon/ticgit (fetch)
        origin    https://github.com/schacon/ticgit (push)

    git remote add <shortname> <url>
        运行 git remote add <shortname> <url> 添加一个新的远程 Git 仓库,同时指定一个你可以轻松引用的简写:

        $ git remote
        origin
        $ git remote add pb https://github.com/paulboone/ticgit
        $ git remote -v
        origin    https://github.com/schacon/ticgit (fetch)
        origin    https://github.com/schacon/ticgit (push)
        pb    https://github.com/paulboone/ticgit (fetch)
        pb    https://github.com/paulboone/ticgit (push)


    git fetch pb
        现在你可以在命令行中使用字符串 pb 来代替整个 URL。
         例如,如果你想拉取 Paul 的仓库中有但你没有的信息,可以运行 git fetch pb:
        $ git fetch pb(拉取 Paul 的仓库中有但你没有的信息,只是拉取,没有和本地修改的合并,要自己手动合并才行)
        remote: Counting objects: 43, done.
        remote: Compressing objects: 100% (36/36), done.
        remote: Total 43 (delta 10), reused 31 (delta 5)
        Unpacking objects: 100% (43/43), done.
        From https://github.com/paulboone/ticgit
         * [new branch]      master     -&gt; pb/master
         * [new branch]      ticgit     -&gt; pb/ticgit
     
    git push [remote-name] [branch-name]
         推送到远程仓库
        当你想分享你的项目时,必须将其推送到上游。 这个命令很简单:git push [remote-name] [branch-name]。 当你想要将 master 分支推送到 origin 服务器时(再次说明,克隆时通常会自动帮你设置好那两个名字),那么运行这个命令就可以将你所做的备份到服务器:
        $ git push origin master
        只有当你有所克隆服务器的写入权限,并且之前没有人推送过时,这条命令才能生效。
         当你和其他人在同一时间克隆,他们先推送到上游然后你再推送到上游,你的推送就会毫无疑问地被拒绝。
         你必须先将他们的工作拉取下来并将其合并进你的工作后才能推送
     
    git remote show [remote-name]
     
         如果想要查看某一个远程仓库的更多信息,可以使用
         $ git remote show origin
        * remote origin
          Fetch URL: https://github.com/schacon/ticgit
          Push  URL: https://github.com/schacon/ticgit
          HEAD branch: master
          Remote branches:
            master                               tracked
            dev-branch                           tracked
          Local branch configured for 'git pull':
            master merges with remote master
          Local ref configured for 'git push':
            master pushes to master (up to date)
        
    git remote rename

        如果想要重命名引用的名字可以运行 git remote rename 去修改一个远程仓库的简写名。 例如,想要将 pb 重命名为 paul,可以用 git remote rename 这样做:
        $ git remote rename pb paul
        $ git remote
        origin
        paul
        值得注意的是这同样也会修改你的远程分支名字。 那些过去引用 pb/master 的现在会引用 paul/master。
        如果因为一些原因想要移除一个远程仓库 - 你已经从服务器上搬走了或不再想使用某一个特定的镜像了,又或者某一个贡献者不再贡献了 - 可以使用 git remote rm :
        $ git remote rm paul
        $ git remote
        origin
        
    git tag
        这个命令以字母顺序列出标签
        $ git tag -a v1.4 -m 'my version 1.4'
        $ git tag
        v0.1
        v1.3
        v1.4
        -m 选项指定了一条将会存储在标签中的信息。 如果没有为附注标签指定一条信息,Git 会运行编辑器要求你输入信息。    

    git show
        $ git show v1.4
        tag v1.4
        Tagger: Ben Straub &lt;ben@straub.cc&gt;
        Date:   Sat May 3 20:19:12 2014 -0700
        my version 1.4
        commit ca82a6dff817ec66f44342007202690a93763949
        Author: Scott Chacon &lt;schacon@gee-mail.com&gt;
        Date:   Mon Mar 17 21:52:11 2008 -0700
            changed the version number
        输出显示了打标签者的信息、打标签的日期时间、附注信息,然后显示具体的提交信息
        
    git tag -a v1.2 9fceb02     
        你也可以对过去的提交打标签。 假设提交历史是这样的:
        $ git log --pretty=oneline
        15027957951b64cf874c3557a0f3547bd83b3ff6 Merge branch 'experiment'
        a6b4c97498bd301d84096da251c98a07c7723e65 beginning write support
        0d52aaab4479697da7686c15f77a3d64d9165190 one more thing
        6d52a271eda8725415634dd79daabbc4d9b6008e Merge branch 'experiment'
        0b7434d86859cc7b8c3d5e1dddfed66ff742fcbc added a commit function
        4682c3261057305bdd616e23b64b0857d832627b added a todo file
        166ae0c4d3f420721acbb115cc33848dfcc2121a started write support
        9fceb02d0ae598e95dc970b74767f19372d61af8 updated rakefile
        964f16d36dfccde844893cac5b347e7b3d44abbc commit the todo
        8a5cbc430f1a9c3d00faaeffd07798508422908a updated readme
        现在,假设在 v1.2 时你忘记给项目打标签,也就是在 “updated rakefile” 提交。 你可以在之后补上标签。 要在那个提交上打标签,你需要在命令的末尾指定提交的校验和(或部分校验和):
        $ git tag -a v1.2 9fceb02
     
     
     
     git push origin --tags(共享标签)
         默认情况下,git push 命令并不会传送标签到远程仓库服务器上。 在创建完标签后你必须显式地推送标签到共享服务器上。 这个过程就像共享远程分支一样 - 你可以运行 git push origin [tagname]。
        $ git push origin v1.5
        Counting objects: 14, done.
        Delta compression using up to 8 threads.
        Compressing objects: 100% (12/12), done.
        Writing objects: 100% (14/14), 2.05 KiB | 0 bytes/s, done.
        Total 14 (delta 3), reused 0 (delta 0)
        To git@github.com:schacon/simplegit.git
         * [new tag]         v1.5 -&gt; v1.5
        如果想要一次性推送很多标签,也可以使用带有 --tags 选项的 git push 命令。 这将会把所有不在远程仓库服务器上的标签全部传送到那里。
        $ git push origin --tags
        Counting objects: 1, done.
        Writing objects: 100% (1/1), 160 bytes | 0 bytes/s, done.
        Total 1 (delta 0), reused 0 (delta 0)
        To git@github.com:schacon/simplegit.git
         * [new tag]         v1.4 -&gt; v1.4
         * [new tag]         v1.4-lw -&gt; v1.4-lw
        现在,当其他人从仓库中克隆或拉取,他们也能得到你的那些标签。
        


        
    git checkout testing
        切换分支

        

    git merge hotfix 合并分支    
        $ git checkout master
        $ git merge hotfix
        
         你可以使用带 -d 选项的 git branch 命令来删除分支
        
        
    git branch -d hotfix 删除临时任务分支
            $ git branch -d hotfix
            Deleted branch hotfix (3a0874c).
            
    合并遇到冲突的解决方法        
        $ git merge iss53
        Auto-merging index.html
        CONFLICT (content): Merge conflict in index.html
        Automatic merge failed; fix conflicts and then commit the result.
        此时 Git 做了合并,但是没有自动地创建一个新的合并提交。 Git 会暂停下来,等待你去解决合并产生的冲突。 你可以在合并冲突后的任意时刻使用 git status 命令来查看那些因包含合并冲突而处于未合并(unmerged)状态的文件:

        $ git status
        On branch master
        You have unmerged paths.
          (fix conflicts and run "git commit")

        Unmerged paths:
          (use "git add &lt;file&gt;..." to mark resolution)

            both modified:      index.html

        no changes added to commit (use "git add" and/or "git commit -a")
     打开文件目录下的文件,保留想要的内容
     
    git branch -v
      如果需要查看每一个分支的最后一次提交,可以运行
    git branch --merged  
      如果要查看哪些分支已经合并到当前分支,可以运行
     
    git branch --no-merged
      查看所有包含未合并工作的分支,可以运行
     
     
    远程分支
    git ls-remote (remote)
        显式地获得远程引用的完整列表
    git remote show
        获得远程分支的更多信息。
     
     
    远程仓库名字 “origin” 与分支名字 “master” 一样,在 Git 中并没有任何特别的含义一样。
    同时 “master” 是当你运行 git init 时默认的起始分支名字,原因仅仅是它的广泛使用,“origin” 是当你运行 git clone 时默认的远程仓库名字。
    如果你运行 git clone -o booyah,那么你默认的远程分支名字将会是 booyah/master。

    git fetch origin
        这个命令查找 “origin” 是哪一个服务器(在本例中,它是 git.ourcompany.com),
        从中抓取本地没有的数据,并且更新本地数据库,移动 origin/master 指针指向新的、更新后的位置。
    git push (remote) (branch)
        如果希望和别人一起在名为 serverfix 的分支上工作,你可以像推送第一个分支那样推送它。
        $ git push origin serverfix
        Counting objects: 24, done.
        Delta compression using up to 8 threads.
        Compressing objects: 100% (15/15), done.
        Writing objects: 100% (24/24), 1.91 KiB | 0 bytes/s, done.
        Total 24 (delta 2), reused 0 (delta 0)
        To https://github.com/schacon/simplegit
         * [new branch]      serverfix -&gt; serverfix

    git push origin use:user_version  推送本地的use分支到远端origin的user_version分支
    (user_version还没创建,推送过后会自动创建)

        
    git checkout -b serverfix origin/serverfix    
        如果想要在自己的 serverfix 分支上工作,可以将其建立在远程跟踪分支之上:
        $ git checkout -b serverfix origin/serverfix
        Branch serverfix set up to track remote branch serverfix from origin.
        Switched to a new branch 'serverfix'
        这会给你一个用于工作的本地分支,并且起点位于 origin/serverfix。
        
        
    运行 git checkout -b [branch] [remotename]/[branch]。 这是一个十分常用的操作所以 Git 提供了 --track 快捷方式:

    $ git checkout --track origin/serverfix
        Branch serverfix set up to track remote branch serverfix from origin.
        Switched to a new branch 'serverfix'


    git checkout -b sf origin/serverfix
        如果想要将本地分支与远程分支设置为不同名字,你可以轻松地增加一个不同名字的本地分支的上一个命令:
        $ git checkout -b sf origin/serverfix
        Branch sf set up to track remote branch serverfix from origin.
        Switched to a new branch 'sf'
        
        
    git branch -u origin/serverfix        
    (本地分支关联并跟踪某个远程分支)
        设置已有的本地分支跟踪一个刚刚拉取下来的远程分支,或者想要修改正在跟踪的上游分支,你可以在任意时间使用 -u 或 --set-upstream-to 选项运行 git branch 来显式地设置。
        $ git branch -u origin/serverfix    
        
    git branch -vv    
        将所有的本地分支列出来并且包含更多的信息,如每一个分支正在跟踪哪个远程分支与本地分支是否是领先、落后或是都有。
        $ git branch -vv
          iss53     7e424c3 [origin/iss53: ahead 2] forgot the brackets
          master    1ae2a45 [origin/master] deploying index fix
        * serverfix f8674d9 [teamone/server-fix-good: ahead 3, behind 1] this should do it
          testing   5ea463a trying something new
          
    git pull=git fetch+git merge    

    git push origin --delete serverfix
         如果想要从服务器上删除 serverfix 分支,运行下面的命令:
        $ git push origin --delete serverfix
        To https://github.com/schacon/simplegit
         - [deleted]         serverfix  

    git rebase master    
        $ git checkout experiment  //转到experiment
        $ git rebase master          //
        First, rewinding head to replay your work on top of it...
        Applying: added staged command
        它的原理是首先找到这两个分支(即当前分支 experiment、变基操作的目标基底分支 master)的最近共同祖先 C2,
        然后对比当前分支相对于该祖先的历次提交,提取相应的修改并存为临时文件,然后将当前分支指向目标基底 C3, 最后以此将之前另存为临时文件的修改依序应用。
        现在回到 master 分支,进行一次快进合并。
        $ git checkout master
        $ git merge experiment
        
        
        ssh-keygen生成公钥和私钥
        cat ~/.ssh/id_rsa.pub 查看公钥
        

    git 报错
    
    error: RPC failed; HTTP 401 curl 22 The requested URL returned error: 401
    fatal: The remote end hung up unexpectedly
    私有项目,没有权限,输入用户名密码,或者远程地址采用这种类型:
    
    https://yourname:password@git.oschina.net/name/project.git
  • 相关阅读:
    关于二进制的利用
    2017年浙江中医药大学程序设计竞赛 Solution
    2018-2019 ACM-ICPC, Asia Xuzhou Regional Contest Solution
    2018-2019 ACM-ICPC, Asia Shenyang Regional Contest Solution
    2018-2019 ACM-ICPC, Asia Nanjing Regional Contest Solution
    AtCoder Grand Contest 029 Solution
    BZOJ 3307: 雨天的尾巴
    Codeforces Round #526 (Div. 2) Solution
    2016-2017 ACM-ICPC Pacific Northwest Regional Contest (Div. 1) Solution
    [HZNUOJ] 博
  • 原文地址:https://www.cnblogs.com/baldermurphy/p/8963238.html
Copyright © 2011-2022 走看看