Git and GitHub 学习笔记 1

“Git Tutorial for beginner” 学习笔记(link

Git Installation

sudo apt-get install git 

Git configuration

git config --global user.name "your name"
git config --global user.email your_email
git config --global core.editor "your_evironment"
git config --global core.autocrlf input  #true for windows, input for Linux/Mac

For more git config information (link) or

git config --help
git config -h

Initializing a Repository

git init

Staging files

git status   #
git add file1 file2/ or .

Committing changes

git commit -m "Initial commit."  #-m message
git commit # type the message in the file.

Each commit should represent a logically step change.
If there is a bug fix and a typo, you need to commit them separately.

Removing Files

rm file_name
git status   # Cannot delete file_name in Git  
git ls-files # show current files in Git
git add file_name
git status   # The file_name has been deleted from Git
git commit -m "Remove unused code."

or you can delete file_name directly by using

git rm file_name

Rename or Moving Files

mv file_name1 file_name2
git status
git add file_name1
git add file_name2
git status              # rename a name

or you can rename file_name1 directly by using

git mv file_name_1 file_name_2
git status
git commit -m "Refactor code"

Ignoring Files

Do not want update your files onto git

echo dir/ > .gitignore
vim .gitignore
# In the file, you can add every files which you don't want to update on git
git status 
git add .gitignore
git commit -m "Add gitignore"

Gitignore on GitHub will show which files don’t need to push on Github.

Viewing the Staged and Unstaged Changes

git diff --staged  # The changes in this stage
git diff # The changes in last operation

Diff Tools

# Setting VScode as default
git config --global diff.tool vscode
git config --global difftool.vscode.cmd "vim --wait --diff $LOCAL $REMOTE"
git config --global -e

# Setting VIM as default
git config --global diff.tool vimdiff
git config --global difftool.prompt false
git config --global alias.d difftool

Open .gitconfig file link.

  • 对所有用户,位于/etc/gitconfig
  • 对于当前用户,位于~/.gitconfig
  • 对于该git仓,位于.git/config

Viewing the History

git log
git log --oneline
git log --oneline --reverse

Viewing a Commit

git show 
git show HEAD~1: file_name
git ls-tree HEAD~1	

Unstaging Files

git restore --staged file_name

Discard local changes

git restore .  #undo all the commit
git clean # git clean -h

Restore a file to early version

git rm file_name
git status -s
git commit -m "delete a file"
git log --oneline
git restore --source=HEAD~1 file_name    # git resotre -h
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Anunnaki_IO

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值