git and github usage

git learning Notes

First, the basic configuration and installation

  • Installation: git landing official website to find the right version installed, or via the command line installation to linux for example: sudo apt-get / yum install git
  • basic configuration:
    • Method 1: Global
      • git config --global user.name 'yourname'
      • git config --global user.email 'youremail'
    • One way: local configuration for a certain warehouse
      • git config --local user.name 'yourname'
      • git config --local user.email 'youremail'
    • Three ways: global configuration, less than basic

      NOTE: When a local provided a warehouse, the warehouse partially disposed in precedence over the global configuration

Second, create a warehouse and basic operation

  • Create a command: git init repository name
  • Create a file: touch filename
  • Save the file to the cache: git add the file name, when more files when you can use git add.
  • Push files to remote buffer from the warehouse: git push origin master
  • View all files in a local folder: ls -al, ls if only to see not only the hidden files.
  • Folder to copy files from the current folder to another file: cp path / filename new_filename
  • View the work area and the staging area of ​​the state: git status
  • View all files in a local folder: ls -al, ls if only to see not only the hidden files.
  • Folder to copy files from the current folder to another file: cp path / filename new_filename
  • View the work area and the staging area of ​​the state: git status

  • Core Area: .git
    • HEAD: on behalf of the entire warehouse is now working on the warehouse
      • HEAD in the .git
      • cd .git into the package
      • View cat HEAD HEAD
      • On which branch from where references are displayed

        ref: refs/heads/master

    • config: In .git directory
      • Into the core area of ​​the directory: cd .git
      • Open the configuration file: vi / cat config
      • Some information modify the configuration file
    • refs:
    • heads: the contents inside are the names of all branches, each of which corresponds to the name of a branch
    • tags: All tags corresponding to the name of this previously submitted

      Each new branch, heads a multi-branch name, each writing a tag, tags in a multi-label name

  • basic structure:
    • commit
      • tree: a tree corresponds to commit only
        • blob file name
      • parent
      • author
      • committer

        By git cat-file interface provided by the label, the unique identification code ASCII good access the content, the specific use is as follows:
        1. git cat-file -t identifiers / labels are obtained corresponding to the type of the object, in git there are three types: commit, tree, blob, blob that article, if the two articles content exactly the same, regardless of whether the same title, will be managed as a git to deal with.
        2.git cat-file -p identifiers / labels is acquired content belongs to a class.

Third, note the separating head pointer

  • Separating the head pointer: refers to the case where no branch is specified, because this situation corresponds when switching branch, the branch name written in the error code generated is less than the case where the branch.
  git命令:git checkout 35e0daa135b08d632ef30ca6a1db9dcfebd0382d
  输出结果:分离头指针下,You are in 'detached HEAD' state.

  M "git\347\254\224\350\256\260.md"
  Note: checking out '35e0daa135b08d632ef30ca6a1db9dcfebd0382d'.

  You are in 'detached HEAD' state. You can look around, make experimental
  changes and commit them, and you can discard any commits you make in this
  state without impacting any branches by performing another checkout.

  If you want to create a new branch to retain commits you create, you may
  do so (now or later) by using -b with the checkout command again. Example:

    git checkout -b <new-branch-name>

  HEAD is now at 35e0daa move readme to readme.md
  • If you continue to develop in the case of separate head pointer, the development of the results is likely to be treated as junk to git rid of, so when switching branches must pay attention to write the name of the branch.
  • git status to view the current status, there is no point to any branch
git status
HEAD detached at 35e0daa
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

    modified:   "git\347\254\224\350\256\260.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:   "git\347\254\224\350\256\260.md"
    modified:   readme.md
  • Filed in the case where the commit separating head pointers, see results git log, the HEAD and branch name is typically bound together, but in a case when the pointer is separated from the head, HEAD appear alone, without any binding branch.

    commit 11f60fdffd0e2ddab6a4cc961f0590386a33967a (HEAD)
    Author: liquanhui02 <[email protected]>
    Date:   Thu Mar 5 17:50:48 2020 0800
    
    add content to readme.md

Fourth, comparing the difference between the two commit

  • Comparative branched distinction need git diff commit1 commit2
  • Branch wording:
    • Two branches of code: the complete identification code or identification code can be part of
    • Use HEAD:
      • HEAD HEAD ~ 1, ~ num represents the first HEAD pushed up several layers, for example, an identifier father
      • HEAD HEAD ^ 1 ^ 1 .. ^ 1 identifies a first layer of pushing up the branch, to write several layers need to be pushed ^ 1

V. deleted branches

  • Normal Delete: git branch -d branch name, this can be a normal delete
  • Forced to delete: git branch -D branch name. When using the -d delete tips really. If deletion using -D, then you need to use the -D

Six of the message submitted for modification

  • The last modification of the message: git commit --amend, enter another interface, save and then exit the revised
  • In addition to modifying the last message outside of a submission:
    • git rebase -i identification code

      Note: this code must be submitted to modify the parent's identification code message, and this requires special attention, most recently submitted can not be used.

    • Into the interface, the need to modify the messge line pick instead reword

    pick 68ce0f7 在master主线上恢复之前误删除的笔记
    reword 7502007 增加修改message内容
    pick d5e6e96 往期message修改
    
    # Rebase 00c4e56..d5e6e96 onto 00c4e56 (3 commands)
    #
    # Commands:
    # p, pick = use commit
    # r, reword = use commit, but edit the commit message
    # e, edit = use commit, but stop for amending
    # s, squash = use commit, but meld into previous commit
    # f, fixup = like "squash", but discard this commit's log message
    # x, exec = run command (the rest of the line) using shell
    # d, drop = remove commit
    #
    # These lines can be re-ordered; they are executed from top to bottom.
    #
    # If you remove a line here THAT COMMIT WILL BE LOST.
    #
    # However, if you remove everything, the rebase will be aborted.
    #
    # Note that empty commits are commented out
    
    • Modify the message content in the second page
    • Appeared in the process of amending the system interruption and other anomalies should be performed rm -fr "/home/liquanhui/tools/git-learning/.git/rebase-merge", submission branches did not submit again to re-rebase
    
    git rebase -i 00c4e5606213ea3938b3c835162157c2b1a7270b
    
    It seems that there is already a rebase-merge directory, and
    I wonder if you are in the middle of another rebase.  If that is the
    case, please try
     git rebase (--continue | --abort | --skip)
    If that is not the case, please
     rm -fr "/home/liquanhui/tools/git-learning/.git/rebase-merge"
    and run me again.  I am stopping in case you still have something
    valuable there.
    
  • Continuous message submitted prior to the merger:
    • git rebase -i identifier

      Note: This identifier and modifications to the top of the message identifier with similar usage, if you want to merge message between 3-5, 2 identifier must be written, that the merger of his father's first message identifies House

    • Leaving a pick in the first jump out of the page, and the rest modified to squash
    • In the message written in merger after the second jump page of the second row, save
    • The last successful merger
    [detached HEAD 278aff8] message修改操作事项
    Date: Thu Mar 5 20:32:45 2020 0800
    1 file changed, 56 insertions(), 42 deletions(-)
    Successfully rebased and updated refs/heads/master.
    liquanhui@ubuntu:~/tools/git-learning$ git log --graph -n4
    
  • No continuous message submitted prior to the merger:
    • git

Guess you like

Origin www.cnblogs.com/ddzc/p/12422966.html