git

  • It is good practice to always review our changes before saving them. We do this using git diff. This shows us the differences between the current state of the file and the most recently saved version:
git diff
  • Git does not track directories on their own, only files within them.
  • See the differences between older commits we can use git diff
# 最近commit和当前的区别
git diff HEAD

# 最近commit的往前一次的commit和当前的区别
git diff HEAD~1 mars.txt

# 最近commit的往前两次次的commit和当前的区别
git diff HEAD~2 mars.txt
  • shows us what changes we made at an older commit as well as the commit message, rather than the differences between a commit and our working directory
# 最近commit做了哪些事
git show HEAD
  • We can also refer to commits using those long strings of digits and letters that git log displays
git diff f22b25e3233b4645dabd0d81e651fe074bd8e73b mars.txt
# 其实用前几位就够了
git diff f22b25e mars.txt
  • restore older versions of things
# 假设只是修改了文件 没有add 没有commit
# 测试了一下 发现add之后也可以restore
git status


# 将文件返回到最近一次commit 当然也可以通过别的HEAD或者log里的ID来返回更靠前的commit
# 不要忘记文件名 不然整个都会被restore
git checkout HEAD mars.txt
  • git revert will create a new commit that reverses Jennifer’s erroneous commit.
    git checkout returns the files within the local repository to a previous state without create a new commit

  • Tell Git to ignore files I don’t want to track
    http://swcarpentry.github.io/git-novice/06-ignore/index.html

  • the Collaborator can use git fetch origin master to get the remote changes into the local repository, but without merging them. Then by running git diff master origin/master the Collaborator will see the changes output in the terminal.

  • Conflict
    http://swcarpentry.github.io/git-novice/09-conflict/index.html

http://swcarpentry.github.io/git-novice/

你可能感兴趣的:(git)