Version Control Command

Version Control Command

0 1981
HashFlare

Git is an open source distributed version control system (DVCS) that can significantly improve the way you work and collaborate on projects. Git allows you to keep a history of the significant changes made to your local files. It can also backup this history through remote hosting services like GitHub.–GitReal

Most of the following contents are more like my mind map rather than a blog, wish can help you some.

git

 Basic Git Command

assume our repository url is git://test.com/repo.git, have two branches:

default branch master and hotfix branch

git clone git://test.com/repo.git   (from default branch)

git config –global user.name “***”

git config –global user.email “***”

git clone -b hotfix –single-branch git://test.com/repo.git
git remote -v
git remote add origin git://test.com/repo.git
git remote set-url origin git://test.com/repo.git

git checkout — folder/
git diff

git show
git reset HEAD (unstage)

git clean -f (remove untracked file: new files,generated files)

git push –set–upstream origin hotfix

git cherry-pick

git stash
git stash list
git stash apply

git push origin hotfix

git branch (-r/-a)

git checkout (-b) master

git fetch / pull
git merge hotfix

git merge –abort

git branch hotfix -d
Basic Branching and Merging https://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging

GIT: FETCH AND MERGE, DON’T PULL http://longair.net/blog/2009/04/16/git-fetch-and-merge/

git log

git log –graph –oneline –decorate –all

https://stackoverflow.com/questions/1057564/pretty-git-branch-graphs

https://git-scm.com/book/zh/v1/Git-%E5%9F%BA%E7%A1%80-%E6%9F%A5%E7%9C%8B%E6%8F%90%E4%BA%A4%E5%8E%86%E5%8F%B2

git show –name-only ********

 

git rebase

branch master & develop

commit changes in develop branch ( don’t push!)

switch to master and git pull

switch to develop git rebase master

if got conflict follow instruction, manually resolve it and git add to mark it as resolved and then git rebase –continue

now is good to do merge

 

dll conflicts

git checkout –theirs — Lib/test.dll

git add Lib/test.dll

.git/index.lock’: File exists. http://stackoverflow.com/questions/7860751/git-fatal-unable-to-create-path-my-project-git-index-lock-file-exists

 

determine remote url

git remote show origin

https://stackoverflow.com/questions/4089430/how-can-i-determine-the-url-that-a-local-git-repository-was-originally-cloned-fr

https://help.github.com/articles/adding-a-remote/

 

track remote branch / link local branch to remote

git push -u origin dev

https://www.git-tower.com/learn/git/faq/track-remote-upstream-branch

https://stackoverflow.com/questions/520650/make-an-existing-git-branch-track-a-remote-branch

Understanding Tracking Branches in Git  https://lornajane.net/posts/2014/understanding-tracking-branches-in-git

 

git branch -vv

git worktree add ../master master

example https://git-scm.com/docs/git-worktree

 

echo “**/.idea/*” >> .gitignore
git status
git add .gitignore
git commit -m “ignore idea subfolders”

git reset HEAD~1 –soft https://stackoverflow.com/questions/19859486/how-to-un-commit-last-un-pushed-git-commit-without-losing-the-changes/19859644

 

git submodule update –init

https://kalyanchakravarthy.net/blog/git-discard-submodule-changes/

git push –delete <remote_name> <branch_name>

git branch -d <branch_name>

 

create pull request

How to Git PR From The Command Line https://hackernoon.com/how-to-git-pr-from-the-command-line-a5b204a57ab1

 

tag

git tag

git checkout tags/v1.0.8

submodule

git submodule update –recursive

subtree

fork and pull request

 

Problem

“git -c diff.mnemonicprefix=false -c core.quotepath=false fetch origin”

1.check if in the middle of merge ( resolve conflicts, merge –abort)

2.If you are running git under a file system that is not case sensitive (Windows or OS X) this will occur if there are two branches with the same name but different capitalisation, e.g. user_model_changes and User_model_changes as both of the remote branches will match the same tracking ref. Delete the wrong remote branch (you shouldn’t have branches that differ only by case) and then git remote prune origin and everything should work

The remote end hung up unexpectedly while git cloning

With this kind of error, I usually start by raising the postBuffer size by:
git config –global http.postBuffer 524288000
(some comments below report having to double the value):
git config –global http.postBuffer 1048576000

http://stackoverflow.com/questions/6842687/the-remote-end-hung-up-unexpectedly-while-git-cloning

3. change remote url

4. add tracking

git branch -u origin/branchname

Tips:

1.create .gitignore using vim .gitignore i ESC :wq

2.delete folder git rm (-r folder name)

git clean -f (to remove the untracked changes) and -fd (to also remove untracked directories) http://stackoverflow.com/questions/61212/remove-local-untracked-files-from-my-current-git-branch

        delete by them: git rm path/to/file

3.revert

a.to revert changes made to your working copy : git checkout .

b.to revert changes made to the index which also called as unstage (i.e., that you have added): git reset  (e.g. git reset HEAD index.html)

git reset did a great job of unstaging octodog.txt, but you’ll notice that he’s still there. He’s just not staged anymore. It would be great if we could go back to how things were before octodog came around and ruined the party.

c.to revert a change that you have committed: git revert

4.origin?master?local branch? remote branch? defalut .git/config(auto edit after clone?)

http://git-scm.com/book/en/v2/Git-Internals-The-Refspec

http://stackoverflow.com/questions/2602546/how-do-i-git-fetch-and-git-merge-from-a-remote-tracking-branch-like-git-pu

5.error: Your local changes to the following files would be overwritten by merge: ****** Please, commit your changes or stash them before you can merge.

a.give up all local changes, and force update with latest source from remote

git fetch –all git reset –hard origin/master

b.only discard specific files which have conflicts

git checkout folderName/fileName.ext  (ext: git checkout <branch_name> — <paths>)

c.fetch and merge

d.git stash git stash pop (By default git stash will not stash files for which there are no history. So if you have files which you have not yet added but which would be overwritten or “created” by the merge, then the merge will still block. In that situation, you can use git stash -u to stash uncommitted files)

http://www.cppblog.com/deercoder/archive/2011/11/13/160007.html

6.Merging vs. Rebasing https://www.atlassian.com/git/tutorials/merging-vs-rebasing

7.error: Ref refs/remotes/origin/dev but expected…

git update-ref -d refs/remotes/origin/dev

8.Git still showing deleted files after a commit

If it lists the files under the “to be committed” section, then just proceed with the commit; the files will remain deleted. (Git tracks deletions too, not just changes.)

If it lists the files under the “changed but not updated” section, then you have two options:

a.Undelete them by restoring the version in the index: git checkout path/to/folder

b.Mark them deleted in Git, then commit: git rm -r path/to/folder

9.display Chinese character

git config core.quotepath false

10.How can I determine the URL that a local Git repository was originally cloned from?

If referential integrity has been broken:

git config –get remote.origin.url
If referential integrity is intact:

git remote show origin
When using git clone (from GitHub, or any source repository for that matter) the default name for the source of the clone is “origin”. Using git remote show will display the information about this remote name.

Tutorial

1.18 Branching Out

When developers are working on a feature or bug they’ll often create a copy (aka. branch) of their code they can make separate commits to. Then when they’re done they can merge this branch back into their main master branch.

We want to remove all these pesky octocats, so let’s create a branch called clean_up, where we’ll do all the work:

git branch clean_up

1.19 Switching Branches

Great! Now if you type git branch you’ll see two local branches: a main branch named master and your new branch namedclean_up.

You can switch branches using the git checkout <branch> command. Try it now to switch to the clean_up branch:

git checkout clean_up

1.23 Preparing to Merge

Alrighty, the moment has come when you have to merge your changes from the clean_up branch into the master branch. Take a deep breath, it’s not that scary.

We’re already on the master branch, so we just need to tell Git to merge the clean_up branch into it:

git merge clean_up

Reference:

Git详解之五 分布式Git

Fast Learning TryGit Online

Git School Git Real

Git How To

 

Practice:

[toggle title=”Toggle Title”]

>>>>>>>>>>>>>>>>>>>>>>>>>

git init

git add / commit -m ” / log

create new folder D/dashboard/Git Cmd/NUS/NUS3

$ git clone ‘/D/dashboard/Git Cmd/NUS/NUS2’
Cloning into ‘NUS2’…
done.

$ cd NUS2

$ git checkout 2d69665fdf18cd852e934eb0a4e597d1a0cfc94f
Note: checking out ‘2d69665fdf18cd852e934eb0a4e597d1a0cfc94f’.

You are in ‘detached HEAD’ state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

git checkout -b new_branch_name

HEAD is now at 2d69665… s

$ git checkout master
Previous HEAD position was 2d69665… s
Switched to branch ‘master’
Your branch is up-to-date with ‘origin/master’.

——————————————————————

$ git tag -a rel1 -m “message”

$ git branch rel1-maint

make changes and commit

$ git checkout rel1-maint
Switched to branch ‘rel1-maint’

make changes and commit

$ git checkout master
Switched to branch ‘master’
Your branch is up-to-date with ‘origin/master’.

$ git merge rel1-maint
Auto-merging test.txt
CONFLICT (content): Merge conflict in test.txt
Automatic merge failed; fix conflicts and then commit the result.

open file:

<<<<<<< HEAD
master
=======

branch
>>>>>>> rel1-maint

fix conflict and commit

————————————————————————

$ git remote add origin https://github.com/lyhistory/NUS.git
fatal: remote origin already exists.

$ git remote rm origin

$ git remote add origin https://github.com/lyhistory/NUS.git

$ git push origin master
Username for ‘https://github.com’: lyhistory
Password for ‘https://lyhistory@github.com’:
To https://github.com/lyhistory/NUS.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to ‘https://github.com/lyhistory/NUS.git’
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., ‘git pull …’) before pushing again.
hint: See the ‘Note about fast-forwards’ in ‘git push –help’ for details.

$ git pull https://github.com/lyhistory/NUS.git

$ git push origin master
Username for ‘https://github.com’: lyhistory
Password for ‘https://lyhistory@github.com’:
Counting objects: 8, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (6/6), 528 bytes | 0 bytes/s, done.
Total 6 (delta 0), reused 0 (delta 0)
To https://github.com/lyhistory/NUS.git
7332965..35c9abb master -> master

————————————————————————

————————————————————————-

git pull https://github.com/lyhistory/NUS.git

$ git push
fatal: No configured push destination.
Either specify the URL from the command-line or configure a remote repository us
ing

git remote add <name> <url>

and then push using the remote name

git push <name>

————————————————————————————————————-

git clone https://github.com/lyhistory/NUS.git

$ git log
commit 733296510c34b8e6115de7d534d9beef9a711db0
Author: Liu Yue <A0135928@u.nus.edu>
Date: Sat Feb 28 14:59:45 2015 +0800

version 2

commit b13bc594981acf6e0567c1c16de27b9f2876e143
Author: Liu Yue <A0135928@u.nus.edu>
Date: Sat Feb 28 14:57:53 2015 +0800

version 1

commit 2df201ad9f933fd248b47287afa0e7d0c8f38454
Author: Liu Yue <lyhistory@gmail.com>
Date: Sat Feb 28 14:33:59 2015 +0800

Initial commit

×××@CR3549 /Z/test/NUS ((7332965…))
$ git checkout b13bc594981acf6e0567c1c16de27b9f2876e143
Previous HEAD position was 7332965… version 2
HEAD is now at b13bc59… version 1

×××@CR3549 /Z/test/NUS ((b13bc59…))

×××@CR3549 /Z/test/NUS ((b13bc59…))
$ git checkout master
Previous HEAD position was b13bc59… version 1
Switched to branch ‘master’
Your branch is ahead of ‘origin/master’ by 2 commits.
(use “git push” to publish your local commits)

×××@CR3549 /Z/test/NUS (master)
$ git log
commit 733296510c34b8e6115de7d534d9beef9a711db0
Author: Liu Yue <A0135928@u.nus.edu>
Date: Sat Feb 28 14:59:45 2015 +0800

version 2

commit b13bc594981acf6e0567c1c16de27b9f2876e143
Author: Liu Yue <A0135928@u.nus.edu>
Date: Sat Feb 28 14:57:53 2015 +0800

version 1

commit 2df201ad9f933fd248b47287afa0e7d0c8f38454
Author: Liu Yue <lyhistory@gmail.com>
Date: Sat Feb 28 14:33:59 2015 +0800

Initial commit

×××@CR3549 /Z/test/NUS (master)
$

——————————————————————————————————————–

[/toggle]

 

Requesting a pull request review https://help.github.com/articles/requesting-a-pull-request-review/

tools:
git for windows
tortoisegit

reference:

git document

git – the simple guide

友荐云推荐