git】 免费开源的版权管理工具【linux】


git branch 查看本地所有分支

git status 查看当前状态

git commit 提交

git branch -a 查看所有的分支

git branch -r 查看远程所有分支

git commit -am "init" 提交并且加注释

git remote add origin git@192.168.1.119:ndshow

git push origin master 将文件给推到服务器上

git remote show origin 显示远程库origin里的资源

git push origin master:develop

git push origin master:hb-dev 将本地库与服务器上的库进行关联

git checkout --track origin/dev 切换到远程dev分支

git branch -D master develop 删除本地库develop

git checkout -b dev 建立一个新的本地分支dev

git merge origin/dev 将分支dev与当前分支进行合并

git checkout dev 切换到本地dev分支

git remote show 查看远程库

git add .

git rm 文件名(包括路径) 从git中删除指定文件

git clone git:github.com/schacon/grit.git 从服务器上将代码给拉下来

git config --list 看所有用户

git ls-files 看已经被提交的

git rm [file name] 删除一个文件

git commit -a 提交当前repos的所有的改变

git add [file name] 添加一个文件到git index

git commit -v 当你用-v参数的时候可以看commit的差异

git commit -m "This is the message describing the commit" 添加commit信息

git commit -a -a是代表add,把所有的change加到git index里然后再commit

git commit -a -v 一般提交命令

git log 看你commit的日志

git diff 查看尚未暂存的更新

git rm a.a 移除文件(从暂存区和工作区中删除)

git rm --cached a.a 移除文件(只从暂存区中删除)

git commit -m "remove" 移除文件(从Git中删除)

git rm -f a.a 强行移除修改后文件(从暂存区和工作区中删除)

git diff --cached 或 $ git diff --staged 查看尚未提交的更新

git stash push 将文件给push到一个临时空间中

git stash pop 将文件从临时空间pop下来


git remote add origin git@github.com:username/Hello-World.git

git push origin master 将本地项目给提交到服务器中


git pull 本地与服务器端同步


git push (远程仓库名) (分支名) 将本地分支推送到服务器上去。

git push origin serverfix:awesomebranch


git fetch 相当于是从远程获取最新版本到本地,不会自动merge

git commit -a -m "log_message" (-a是提交所有改动,-m是加入log信息) 本地修改同步至服务器端 :

git branch branch_0.1 master 从主分支master创建branch_0.1分支

git branch -m branch_0.1 branch_1.0 将branch_0.1重命名为branch_1.0

git checkout branch_1.0/master 切换到branch_1.0/master分支

du -hs

git branch 删除远程branch

git push origin :branch_remote_name

git branch -r -d branch_remote_name


初始化版本库,并提交到远程服务器端

mkdir WebApp

cd WebApp

git init 本地初始化

touch README

git add README 添加文件

git commit -m 'first commit'

git remote add origin git@github.com:daixu/WebApp.git

git】 free and open source distributed version control system【linux】


To set your identity:

git config --global user.name "John Doe"

git config --global user.email johndoe@example.com

To set your editor:

git config --global core.editor emacs

To enable color:

git config --global color.ui true

To stage all changes for commit:

git add --all

To stash changes locally, this will keep the changes in a separate changelist

called stash and the working directory is cleaned. You can apply changes

from the stash anytime

git stash

To stash changes with a message

git stash save "message"

To list all the stashed changes

git stash list

To apply the most recent change and remove the stash from the stash list

git stash pop

To apply any stash from the list of stashes. This does not remove the stash

from the stash list

git stash apply stash@{6}

To commit staged changes

git commit -m "Your commit message"

To edit previous commit message

git commit --amend

Git commit in the past

git commit --date="date --date='2 day ago'"

git commit --date="Jun 13 18:30:25 IST 2015"

more recent versions of Git also support --date="2 days ago" directly

To change the date of an existing commit

git filter-branch --env-filter \

    'if [ $GIT_COMMIT = 119f9ecf58069b265ab22f1f97d2b648faf932e0 ]

     then

         export GIT_AUTHOR_DATE="Fri Jan 2 21:38:53 2009 -0800"

         export GIT_COMMITTER_DATE="Sat May 19 01:01:01 2007 -0700"

     fi'

To removed staged and working directory changes

git reset --hard

To go 2 commits back

git reset --hard HEAD~2

To remove untracked files

git clean -f -d

To remove untracked and ignored files

git clean -f -d -x

To push to the tracked master branch:

git push origin master

To push to a specified repository:

git push git@github.com:username/project.git

To delete the branch "branch_name"

git branch -D branch_name

To make an existing branch track a remote branch

git branch -u upstream/foo

To see who committed which line in a file

git blame filename

To sync a fork with the master repo:

git remote add upstream git@github.com:name/repo.git # Set a new repo

git remote -v # Confirm new remote repo

git fetch upstream # Get branches

git branch -va # List local - remote branches

git checkout master # Checkout local master branch

git checkout -b new_branch # Create and checkout a new branch

git merge upstream/master # Merge remote into local repo

git show 83fb499 # Show what a commit did.

git show 83fb499:path/fo/file.ext # Shows the file as it appeared at 83fb499.

git diff branch_1 branch_2 # Check difference between branches

git log # Show all the commits

git status # Show the changes from last commit

Commit history of a set of files

git log --pretty=email --patch-with-stat --reverse --full-index -- Admin*.py > Sripts.patch

Import commits from another repo

git --git-dir=../some_other_repo/.git format-patch -k -1 --stdout | git am -3 -k

View commits that will be pushed

git log @{u}..

View changes that are new on a feature branch

git log -p feature --not master

git diff master...feature

Interactive rebase for the last 7 commits

git rebase -i @~7

Diff files WITHOUT considering them a part of git

This can be used to diff files that are not in a git repo!

git diff --no-index path/to/file/A path/to/file/B

To pull changes while overwriting any local commits

git fetch --all

git reset --hard origin/master

Update all your submodules

git submodule update --init --recursive

Perform a shallow clone to only get latest commits

(helps save data when cloning large repos)

git clone --depth 1

To unshallow a clone

git pull --unshallow

Create a bare branch (one that has no commits on it)

git checkout --orphan branch_name

Checkout a new branch from a different starting point

git checkout -b master upstream/master

Reset local branch to upstream branch and then checkout it

git checkout -B master upstream/master

Remove all stale branches (ones that have been deleted on remote)

So if you have a lot of useless branches, delete them on Github and then run this

git remote prune origin

The following can be used to prune all remotes at once

git remote prune $(git remote | tr '\n' ' ')

Revisions can also be identified with :/text

So, this will show the first commit that has "cool" in their message body

git show :/cool

Undo parts of last commit in a specific file

git checkout -p HEAD^ -- /path/to/file

Revert a commit and keep the history of the reverted change as a separate revert commit

git revert

Pick a commit from a branch to current branch. This is different than merge as

this just applies a single commit from a branch to current branch

git cherry-pick

Undo last commit

If you want to nuke commit C and never see it again

(F)

A-B-C

master

git reset --hard HEAD~1

Undo last commit

If you want to undo the commit but keep your changes

(F)

A-B-C

master

git reset HEAD~1

list files changed in NULL

git diff-tree --no-commit-id --name-only -r NULL

list files changed in NULL, porcelain way, meant to be user facing

git show --pretty="" --name-only bd61ad98

See everything you have done, across branches, in a glance,

then go to the place right before you broke everything

git reflog

git reset HEAD@{hash}

To move your most recent commit from one branch and stage it on TARGET branch

git reset HEAD~ --soft

git stash

git checkout TARGET

git stash pop

git add .


腾图小抄 SCWY.net v0.03 小抄561条 自2022-01-02访问368006次