Learn GIT

来源:互联网 发布:21天学通c语言电子版 编辑:程序博客网 时间:2024/04/30 12:33

Git是目前世界上最先进的分布式版本控制系统。

一、Git Workflow

1.git init:creates a new Git repository

2.git status:inspects the contents of the working directory and staging area

3.git add:adds files from the working directory to the staging area

4.git diff:shows the different between the working directory and the staging area

5.git commit:permanently stores file changes from the staging area in the repository

6.git log:shows a list of all previous commits

这里写图片描述

二、3 different ways to backtrack

1.git checkout HEAD filename:Discards changes in the working directory.

2.git reset HEAD filename:Unstages file changes in the staging area.

3.git reset SHA:Can be used to reset to a previous commit in your commit history.

三、Git Branching

1.git branch:Lists all a Git project’s branches

2.git branch branch_name:Creates a new branch

3.git checkout branch_name:Used to switch from one branch to another

4.git merge branch_name:Used to join file changes from one branch to another

5.git branch -d branch_name:Deletes the branch specified

四、Git Teamwork

1.git clone:Creates a local copy of a remote

2.git remote -v:Lists a Git project’s remote

3.git fetch:Fetches work from the remote into the local copy.

4.git merge origin/master:Merges origin/master into your local branch.

5.git push origin :Pushes a local branch to the origin remote.

Git projects are usually managed on Github, a website that hosts Git projects for millions of users. With Github you can access your projects from anywhere in the world by using the basic workflow you learned here.


PS:

1.怎么将本地文件上传到github?

  • github上创建一个资源
  • 切换到你本地目录下
  • git init
  • git remote add origin xxxx.git //xxx.git就是你在远程github上创建资源http地址
  • git add .
  • git commit -m ‘add’
  • git push origin master
  • finish

2.如何用git创立自己的项目?

Step 1: Create the README file

In the prompt, type the following code:mkdir ~/Hello-World# Creates a directory for your project called "Hello-World" in your user directorycd ~/Hello-World# Changes the current working directory to your newly created directorygit init# Sets up the necessary Git files# Initialized empty Git repository in /Users/you/Hello-World/.git/touch README# Creates a file called "README" in your Hello-World directory

Step 2: Commit your README
git add README
# Stages your README file, adding it to the list of files to be committed

git commit -m 'first commit'# Commits your files, adding the message "first commit"

Step 3: Push your commit
git remote add origin https://github.com/username/Hello-World.git

# Creates a remote named "origin" pointing at your GitHub repositorygit push origin master# Sends your commits in the "master" branch to GitHub
0 0
原创粉丝点击