BASIC COMMANDS
git init <directory> # creates .git folder in your projectgit clone <repo> # clone repo
git config user.name <name>
git config --global user.name "FIRST_NAME LAST_NAME"
git config --global user.email "MY_NAME@example.com"
git config --global alias.ci commit #creates alias ci command that equals git commit
git add <directory>/$filename/./*.c # add new or modified files to the index
git commit -am "message" #record changes to repository, -a=all files, -m=message
git status # list which files are staged, unstaged and untracked.
git log # shows commit history
git diff # show unstaged changes between your index and working directory
git pull # fetch from and integrate with another repository or a local branch
git pull --rebase #when true, rebase the current branch on top of the upstream branch after fetching.
git tag # listing the existing tags
git tag v1.4 #lightweight tag - pointer to a specific commit
git tag -a v1.4 -m "Message"#annotated tags are stored as full objects in GIT db
git tag # listing the existing tags
git tag v1.4 #lightweight tag - pointer to a specific commit
git tag -a v1.4 -m "Message"#annotated tags are stored as full objects in GIT db
git rm # to remove a file from git
gitk # check commit tree in gui
.gitignore # add here files to ignore
gitk # check commit tree in gui
.gitignore # add here files to ignore
UNDOING CHANGES
git revert <commit> # create new commit that undoes all of the changes made in <commit>, then apply it to the current branchgit reset <file> # unstages file without overwriting any changes
git clean -n #Remove untracked files from the working tree
REVERTING GIT HISTORY
git commit --ammend # change recent commit message
git rebase <base> # rebase the current branch onto <base>. Base can be a commit ID, a branch name or a tag
git reflog # show log of changes to the local repository`s HEAD
GIT BRANCHES
git branch #check what branch you atgit branch -d $branchname # deletes branch
git checkout master (stable) # Switch branches or restore working tree files
git checkout -b $newbranchname # create new branch
git merge <branch> # Join two or more development histories together
REMOTE REPOSITORIES
git remote add <name> <url> #new connection to a remote repo. Name is shortcut to repo
git fetch <remote> <branch> #the command goes out to that remote project and pulls down all the data from that remote project that you don’t have yet.
git pull <remote> #Fetch from and integrate with another repository or a local branch
git push <remote> <branch> # Update remote refs along with associated objects
git push origin master # push to repository master branch
git fetch <remote> <branch> #the command goes out to that remote project and pulls down all the data from that remote project that you don’t have yet.
git pull <remote> #Fetch from and integrate with another repository or a local branch
git push <remote> <branch> # Update remote refs along with associated objects
git push origin master # push to repository master branch
git remote update #update all your remote branches
ROLL BACK 1 COMMIT or a few:
git reset Head ~1 # unstage last changings
git reset --hard commitIDNumber # roll back to specified commit
git reset --hard commitIDNumber # roll back to specified commit
git push --force origin stable
git pull --rebase
git merge master --no-ff
git reset --hard HEAD~1 # throw away any uncommitted changes you have
MERGE MASTER TO STABLE
git checkout stablegit pull --rebase
git merge master --no-ff
REVERT MERGE that was committed but didnt pushed
git reset --hard HEAD~1 # throw away any uncommitted changes you have
COMMIT TEXT SHOULD:
* Start from capital letter
* Be in imperative mood (В повелительном наклонении (Change custom))
* At the end add task reference with: refs #1234567 (task number)
MIGRATE REPO
git clone --mirror $GIT_SERVER_FROM$/${REPOS_GITHUB[$r]}.gitcd ${REPOS_GITHUB[$r]}.git
git remote set-url origin $GIT_SERVER_TO$/${REPOS_GITLAB[$r]}.git
git push --mirror -u origin
Rename branch
go to the branch
> git branch dev-v1
> git branch -m old-name new-name
> git branch -m dev-v1 dev
> git push origin :dev-v1 devs
Git filename is too long
Git filename is too long
> git clone -c core.longpaths=true
Комментариев нет:
Отправить комментарий