git 使用整理

来源:互联网 发布:断电mysql修复 编辑:程序博客网 时间:2024/06/06 01:39
  1. 一般来说,HEAD 指针指向的是当前分支的最新版本。
  2. create a remote Git branch
    1.git checkout -b feature/sh
    2.git push origin feature/sh
  3. 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=======
  4. 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 :)


  5. merge a git branch into master

    git checkout mastergit pull origin mastergit merge testgit push origin master

  6. git merge origin/fe
  7. how to undo a git commit --amend

    git reset --soft @{1}
  8. git checkout branch_name //切换到branch_name 的branch
  9. git checkout -- file.txt 替换掉本地的改动
  10. git log --pretty=oneline file.name
  11. git show 即可显示具体的某次的改动的修改
  12. git remote -v 查看远程仓库地址
  13. git branch 查看当前branch
  14. git branch -a //查看所有分支
  15. git reset HEAD a.txt//取消暂存文件
  16. git reset HEAD CONTRIBUTING.md
  17. git diff --cached 比较暂存区和版本库中上次提交的差异
  18. git diff --staged //比较的是工作目录中当前文件和暂存区域快照之间的差异
  19. git diff --full-index HEAD~ HEAD > /tmp/1.txt  //本次commit和上次提交到repo的差异
  20. git diff --name-only
    HEAD~ (which is the very first commit made to the repository), you can use eitherHEAD~~ orHEAD~2
  21. HEAD^ means the first parent of the tip of the current branch.
  22. git rm file1.txt 删除git (本地和远程)数据仓库的文件
  23. git mv:移动文件
  24. git commit --amend //修改最后一次提交
  25. git reset --hard commit_id // 彻底回退到某个版本,本地的源码也会变为上一个版本的内容
  26. git pull以在你的工作目录中 获取(fetch) 并 合并(merge) 远端的改动。
  27. git pull origin feature/1 //从分支拉取并合并代码
  28.  git fetch origin feature/1 从分支拉取代码
  29. git merge origin/feature/ 
  30. git push origin master
  31. git stash 将文件给push到一个临时空间中
  32. git stash pop //将文件从临时空间pop下来
  33. git merge master 合并master分支到当前branch
  34. git status
  35. git submodule update --init --recursive

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 stashgit checkout some-branchgit stash pop

若讀者想確認設定值,可使用 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
0 0
原创粉丝点击