xuesn 发表于 2018-9-19 06:55:34

Setting up a Git project

Setting up a Git projecthttp://git.or.cz/gitwiki/QuickStart  If you want to work with an existing project, clone it:
$ git clone   If you do not have an existing git project, create one:
$ cd project/  $ git init          # initializes the repository
  $ git add .         # add those 'unknown' files
  $ git commit      # commit all changes, edit changelog entry
  Git will look for a file named .gitignore in the root of your repository which contains a set of shell patterns to ignore in file paths.
Branching and merging$ git checkout -b linux-work      # create a new branch named "linux-work"  $
  $ git commit -a
  $ git checkout master               # go back to master branch
  $ git merge linux-work            # merge changesets from linux-work (Git >= 1.5)
  $ git pull . linux-work             # merge changesets from linux-work (all Git versions)
Importing patches$ git apply < ../p/foo.patch  $ git commit -a
Exporting a patch$   $ git commit -a -m &quot;commit message&quot;
  $ git format-patch HEAD^# creates 0001-commit-message.txt
  # (HEAD^ means every patch since one revision before the
  # tip of the branch, also known as HEAD)
Network support# clone from the primary Git repo  foo$ git clone git://git.kernel.org/pub/scm/git/git.git
  foo$ cd git
  # pushing changes to a remote repo with SSH
  foo$ git push user@example.com:my-repository.git/
  # fetch changes to a remote branch into a local branch
  foo$ git fetch user@example.com:my-repository.git/ remote-branch:local-branch
  # merge changes from a remote machine
  bar$ git pull git://foo/repo.git/ branch
  # Serve repository via git protocol
  foo$ cd /my/repository/
  foo$ touch .git/git-daemon-export-ok
  foo$ git daemon# now others can fetch from git://your.machine/my/repository/.git/
  # Set up a bare (= without working directory) repository (e.g. on a webserver)
  foo$ mkdir my-repo.git
  foo$ cd my-repo.git
  foo$ git --bare init
  foo$ chmod a+x hooks/post-update # this is needed for HTTP transport
  # you need to populate this repository via push
Inspecting revisions# inspect history visually  foo$ gitk       # this opens a Tk window, and shows you how the revisions are connected
  # inspect history
  foo$ git log    # this pipes a log of the current branch into your PAGER
  foo$ git log -p # ditto, but append a patch after each commit message
  # inspect a specific commit
  foo$ git show HEAD    # show commit info, diffstat and patch
  # of the tip of the current branch
Referring to revisions# by name  foo$ git log v1.0.0   # show history leading up to tag &quot;v1.0.0&quot;
  foo$ git log master   # show history of branch &quot;master&quot;

  #>  foo$ git show master^   # show parent to last revision of master
  foo$ git show master~2# show grand parent to tip of master

  foo$ git show master~3# show great grand parent to tip of master (you get the>  # by output of &quot;git describe&quot;
  foo$ git show v1.4.4-g730996f# you get this string by calling &quot;git describe&quot;

  # by hash (internally, all objects are>  foo$ git show f665776185ad074b236c00751d666da7d1977dbe
  foo$ git show f665776   # a unique prefix is sufficient
  # tag a revision
  foo$ git tag v1.0.0                      # make current HEAD known as &quot;v1.0.0&quot;
  foo$ git tag interesting v1.4.4-g730996f # tag a specific revision (not HEAD)
Comparing revisions# diff between two branches  foo$ git diff origin..master            # pipes a diff into PAGER
  foo$ git diff origin..master > my.patch # pipes a diff into my.patch
  # get diffstat of uncommitted work
  foo$ git diff --stat HEAD
Cherry picking patchesfoo$ git cherry-pick other-branch~3   # apply 4th last patch of other-branch to current branch
页: [1]
查看完整版本: Setting up a Git project