标签 git 下的文章

undo last commit ( most recent commit) to your local repository:

git reset --hard HEAD~1

或者先看一下commit的编号,然后把你想要退回的commit编号记录一下,然后:

git reset --hard REF/commit-no

这么做是有风险的,请务必git status命令看一下当前是否有未保存的改动!

那么本地改好了,怎么推送到remote呢?

- 阅读剩余部分 -

git log --pretty=format:"%cn made a commit %h on %ad - %s" --date=short

如果需要过滤,就可以用pipe符号|,然后后面用grep来匹配字符串。
关于grep,如果要反向匹配,就是说,不含有某个字符,用grep -v

我理解就是,tag就是一个快照(snapshot),是某个repo的一个定点的状态;branch就是一段录像,反应了一段时间范围内的变化(多个commit组成了一个开发变化的过程)。

A tag represents a version of a particular branch at a moment in time. A branch represents a separate thread of development that may run concurrently with other development efforts on the same code base. Changes to a branch may eventually be merged back into another branch to unify them.

From the theoretical point of view:

  • tags are symbolic names for a given revision. They always point to the same object (usually: to the same revision); they do not change.
  • branches are symbolic names for line of development. New commits are created on top of branch. The branch pointer naturally advances, pointing to newer and newer commits.

- 阅读剩余部分 -

大家在用git的时候可能会出现两种情况:

  • 在初始化git仓库的时候没有创建.gitignore文件
  • 中间提交或生成了某个文件(比如log),但忘了加入到.gitignore

这二种情况都会导致把不必要、不想要的文件也都commit到repo里了。
然而,这些文件已经被提交了, 这时候再创建.gitignore文件,或者把文件添加到.gitignore文件, 尝试着去忽略这些文件时,会发现ignore的规则对那些已经被commit(track)的文件无效,这些不想要的文件仍然在仓库里。

解决方案是:

- 阅读剩余部分 -

啥也不说,就这段代码,贴到.bashrc

function git_branch {
   branch="`git branch 2>/dev/null | grep "^\*" | sed -e "s/^\*\ //"`"
   if [ "${branch}" != "" ];then
       if [ "${branch}" = "(no branch)" ];then
           branch="(`git rev-parse --short HEAD`...)"
       fi
       echo " ($branch)"
   fi
}

export PS1="\[\033[01;32m\]\[email protected]\h\[\033[01;34m\] \w\[\033[31m\]\$(git_branch)\[\033[00m\] $ "

- 阅读剩余部分 -