git 使用整理

  1. 一般来说,HEAD 指针指向的是当前分支的最新版本。
  2. create a remote Git branch
    1.git checkout -b feature/sh
    2.git push origin feature/sh
  3. delete a git branch
    git branch -d topic/branch
    git branch -D topic/branch
    git push origin --delete topic/branch
  4. git change to tag
    git fetch --all --tags --prune
    git checkout tag_name
     
  5. A conflict-marked area begins with <<<<<<< and ends with >>>>>>>. These are also known as the conflict markers. The two conflicting blocks themselves are divided by a=======
  6. git checkout -- path/to/file

    And that undoes any changes to the file.

    An even easier way to undo all unstaged changes on current working directory [1]:

    git checkout -- .
    

    [1] - Be warned - you will lose any other unstaged changes you were working on (if any). If you don't know what you are doing, then keep a backup of the files you were working on :)

  7. merge a git branch into master
    git checkout master
    git pull origin master
    git merger test
    git push origin master
  8. how to undo a git commit --amend
    git reset --soft @{1}
  9. git merge origin/fe
    
  10. git checkout branch_name //切换到branch_name 的branch
  11. git checkout -- file.txt 替换掉本地的改动
  12. git log --pretty=oneline file.name

    --oneline

    This is a shorthand for "--pretty=oneline --abbrev-commit" used together.

  13. git show 即可显示具体的某次的改动的修改
  14. git remote -v 查看远程仓库地址
  15. git branch 查看当前branch
  16. git branch -a //查看所有分支
  17. git reset HEAD a.txt//取消暂存文件
  18. git reset HEAD CONTRIBUTING.md
  19. git diff --cached 比较暂存区和版本库中上次提交的差异
  20. git diff --staged //比较的是工作目录中当前文件和暂存区域快照之间的差异
  21. git diff --full-index HEAD~ HEAD > /tmp/1.txt  //本次commit和上次提交到repo的差异
  22. git diff --name-only
    HEAD~ (which is the very first commit made to the repository), you can use eitherHEAD~~ orHEAD~2
  23. HEAD^ means the first parent of the tip of the current branch.
  24. git rm file1.txt 删除git (本地和远程)数据仓库的文件
  25. git mv:移动文件
  26. git commit --amend //修改最后一次提交
  27. git reset --hard commit_id // 彻底回退到某个版本,本地的源码也会变为上一个版本的内容
  28. git pull以在你的工作目录中 获取(fetch) 并 合并(merge) 远端的改动。
  29. git pull origin feature/1 //从分支拉取并合并代码
  30.  git fetch origin feature/1 从分支拉取代码
  31. git merge origin/feature/ 
  32. git push origin master
  33. git stash 将文件给push到一个临时空间中
  34. git stash pop //将文件从临时空间pop下来
  35. git merge master 合并master分支到当前branch
  36. git status
  37. $ git archive -o repo.tar --remote=<repo url> <commit id>
    git submodule update --init --recursive
  38. git config commit.template   [模板文件名]    //这个命令只能设置当前分支的提交模板
    git config  — —global commit.template   [模板文件名]    //这个命令能设置全局的提交模板,注意global前面是两杠

 

error and solve method:

 

  1. OSError: Failed to delete remote.origin.url: error: could not lock config file .git/config: Permission denied                  chmod -R user:group folder
  2. Git: “Not currently on any branch.” Is there an easy way to get back on a branch, while keeping the changes?

  3. git stash
    git checkout some-branch
    git stash pop
  4. GIT_DISCOVERY_ACROSS_FILESYSTEM not set
    solved: git init

     

若讀者想確認設定值,可使用 git config --list 命令列出所有Git能找到的設定值:

remove an entry in global configuration with git config?

 

I'm not sure what you mean by "undo" the change. You can remove the core.excludesfile setting like this:

git config --global --unset core.excludesfile

And of course you can simply edit the config file:

git config --global --edit

 

 

 

Git Properties

 

Repository information can be set in a reviewboard.url property on the Git tree. Users may need to do this themselves on their own Git tree, so in some cases, it may be ideal to use dotfiles instead.

To set the property on a Git tree, type:

$ git config reviewboard.url http://reviewboard.example.com

 

 

 

A useful configuration to set is "color.ui". When set to "auto", Git will use text colors to highlight status information, e.g., untracked files will be displayed in red for "git status":

    $ git config --global color.ui auto--global color.ui auto
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值