DaidalosCheung / notes

0 stars 0 forks source link

Git & Github #1

Open DaidalosCheung opened 6 years ago

DaidalosCheung commented 6 years ago

- Git

- Github

DaidalosCheung commented 6 years ago
  1. Open terminal
  2. Type the command sudo ipsec up [vpn-name]
  3. Press Return
DaidalosCheung commented 4 years ago

1. Initialize respiratory

  1. $ cd /home/user/my_project (Go to target respiratory)

    1. For empty folder: $ git init 我们只是做了一个初始化,项目文件尚没有被跟踪_

    2. For non-empty folder: *$ git add 「.c」 $ git add LICENSE $ git commit -m 'initial project version'**

    3. Clone respiratory already existed: $ git clone https://github.com/libgit2/libgit2 将在当前路径里创建一个 “libgit2” 的文件夹,并将远程仓库内容复制进去 $ git clone https://github.com/libgit2/libgit2 mylibgit 与上一致,远程仓库的文件将会复制进 “mylibgit” 文件夹

2. Add file track it

  1. $ git status 检视当前所有文件夹的 git 状态,状态分为 tracked 和 untracked:

    • untracked, 标志文件未被跟踪,它既不在 staging area 也不在既往 snapshot 里面
    • tracked,标志文件已经在 git 仓库里面
      • unmodified
      • modified
      • staged
        $ git status
        On branch master
        Your branch is up-to-date with 'origin/master'.
        nothing to commit, working directory clean

        clean 表示所有的更改都已经保存

  2. $ git add "add precisely this content to the next commit”, can be applied in multipurpose:

    1. Begin tracking new files;
    2. Stage files;
    3. Other purposes like merge-conflict files as resolved
  3. $ git diff To see what you’ve changed but not yet staged

    1. $ git diff --staged 显示已经 staged 过的文档内容
    2. $ git diff --cached 同上
  4. $ git add . add all new update into staged

  5. $ git commit -m "我增加了一个修改"

      [master 3d7bdf2] 我增加了一个修改
      1 file changed, 2 insertions(+)

    Which branch you committed to [master], what SHA-1 checksum the commit has [3d7bdf2]

  6. $ git commit --amend 撤销上一次递交,注意此操作不可恢复

  7. $ git rm

    1. $ git rm log/*.log Note the backslash (\ ) in front of the * . This is necessary because Git does its own filename expansion in addition to your shell’s filename expansion. This command removes all files that have the .log extension in the log/ directory. Or, you can do something like this:
    2. $ git rm *~ This command removes all files whose names end with a ~ .
  8. $ git log -p -2 显示最近2次更改记录,并以补丁(--patch)显示修改的内容 $ git log --stat $ git log --pretty=oneline 一行内显示简要内容 $ git log --pretty=format:"%h %s" --graph 显示简要哈希值(%h),显示提交说明(%s), 并且以图例方式显示分支与合并 详情请见 Git 的 53 页

    commit 3d7bdf2ca274bec78dc401ff98de8ab5b6cc7dc7 (HEAD -> master)
    Author: Ray Cheung [daidalos@link.cuhk.edu.hk]
    Date:   Mon Oct 26 23:33:14 2020 -0400
    
    This is the 2nd test commit
    
    commit 68af1c36d25d35d7ce56cc504ccc0ea91e1e3dbc
    Author: Ray Cheung [daidalos@link.cuhk.edu.hk]
    Date:   Mon Oct 26 23:32:00 2020 -0400
    
    This is the 1st commit

    One of the more helpful options is -p or --patch, which shows the difference (the patch output) introduced in each commit. You can also limit the number of log entries displayed, such as using -2 to show only the last two entries.

    1. $ git log -p -2
  9. $ git checkout [Hash] 回滚到某一个版本。

无论是 git checkout 还是 git diff 都可以使用 hash value 来追踪和比对

3. remote

$ git remote add [shortname][url] 从[url]添加一个新的远程 Git 仓库,同时指定一个方便使用的简写 [shortname] $ git remote show [remote] 查看当前的 [remote] 的相关信息

ray@ray-ThinkPad-T440p:~/Desktop/Coding/Python$ git remote show try_git
* remote try_git
  Fetch URL: https://github.com/DaidalosCheung/Python.git
  Push  URL: https://github.com/DaidalosCheung/Python.git
  HEAD branch: master
  Remote branch:
    master 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)
  1. 从线上获取文件
    1. $ git fetch pb 现在可以用这条命令获取服务器上的新内容,“pb” 指代[url]
    2. $ git pull pb 与以上类似,git pull 命令会自动抓取服务器上数据后合并该远程分支到当前分支
  2. 推送文件至线上
    1. $ git push [remote][branch] 可以将 master [branch] 的内容备份到 origin [remote] 服务器 如果是多人合作,出现错误,原因可能是你必须先抓取他们的工作将其合并进你的工作后才能推送
DaidalosCheung commented 4 years ago

查找什么文件已经被 staged 了