Version Control Systems
- Details
- Category: Version Control Systems
- Hits: 2275
Here are some useful commands for everyday tasks with mercurial.
- Details
- Category: Version Control Systems
- Hits: 34294
In the GIT Bash shell open the global configuration file with:
vi ~/.gitconfig
The add the following lines to the file:
[difftool "kdiff3"] path = C:/Program Files (x86)/KDiff3/kdiff3.exe trustExitCode = false [difftool] prompt = false [diff] tool = kdiff3 [mergetool "kdiff3"] path = C:/Program Files (x86)/KDiff3/kdiff3.exe trustExitCode = false [mergetool] keepBackup = false [merge] tool = kdiff3
You would have to change the paths to point to the directory where Kdiff3 is installed.
Save and make a modification on a file. Then you can check if everything is correctly configurated with:
git difftool
- Details
- Category: Version Control Systems
- Hits: 2868
GIT: Basic Commands
git clone <url> Creates a local copy of a remote repository.
git pull Brings changes from the remote repositoriy to our local repository.
git status Shows the changed, deleted und untracked files.
git add -A <path>Marks all the changes in the path for commiting. It adds the changes to the staging area.
git commit -m <Message> Commits the changes in the stage area to the local repository. This commit is local, you have to push your changes to send it to the remote repository.
git push Sends changes from our local repository to the remote repository.
git checkout -- <path> CAUTION: Reverts all the local changes on the path.
GIT Flow
For large projects I would recommend to use this git extension because it simplifies the creation of release, feature and hotfix branches.
GIT: Common use cases
Analyse the merge history
Git can show a very nice graph the merges and branches:
git log --graph --oneline --decorate --all
It can be configurate as an alias:
git config --global --add alias.graph "log --graph --oneline --decorate --all"
git graph It shows the same a the first comand.
If you want to see the commiter's name and commit's date, you could use:
git config --global --add alias.graph "log --graph --all --pretty=format:\"%C(yellow)%h%Creset%C(cyan)%C(reset)%C(auto)%d%Creset%C(cyan)(%cr)%Creset %C(green)%cn%Creset %s\""
It comes an important issue, when you are working on another ticket
This saves current changes in the working copy to a temporary special area
git stash Save changes
git stash save "message" Save changes with a message
git stash pop Restore the changes.
Restore files
The file RestServiceSetup.impex was deleted on the commit 99f17d151b09ac6446d3edfd7fa00a2c79b58042. We restore it with the following command:
git checkout 99f17d151b09ac6446d3edfd7fa00a2c79b58042~1 ./RestServiceSetup.impex
Remove untracked files or directories
git clean -i Remove files using a UI
git clean -f Remove untracked files from the working copy
git clean -d Remove directories files from the working copy
Remove last Commit
If it wasn't pushed into the remote repository:
git reset --soft HEAD~1
If it is already in the remote repository
git revert HEAD
Revert a merge
If it wasn't pushed, you can reset --hard it.
If it was pushed, there isn't any easy way to revert it. Here is a very good explanation for Git applicable Revert a faulty merge
The solution that I use is to revert the data changes and then create a new feature branch with the old changes.
See the changes done in a merge
If the merge has the hash 1bb63c, you can use:
git diff 1bb63c^1 1bb63c git diff 1bb63c^2 1bb63c
To see the differences with the first and second parent.
Move a branch to a different commit
Brnaches are references in git. If you forgot to create a feature branch and you commited in develop, you can create a new feature branch and then move it to the last commit
git branch -f feature/IN-117 c8ef8ba
where c8ef8ba is the last commit which goes in the feature branch
Then you have to set the branch develop back
git branch -f develop 3fd1eff
where 3fd1eff is the last commit belonging to develop.
This will only work if the local changes weren't pushed.
Remove local branches which don't exist in the remote repository
After working with features branches for a while git branch -a will show some branches which don't exist in the remote repository. Because this is a command which work locally, it may show outdated information.
To remove all your local branches, which don't exist in the remote run the followoing command:
git remote prune origin
Create a patch of a feature branch
Yes, you have to commit your changes if you want to include them in the patch.
git format-patch <feature_branch_name> //Creates the patch(es)
git apply <patch_name>.patch //Applies the patch in your current branch.
Subversion (SVN)
The master branch is pointing to the wrong branch in the SVN repository
git checkout br-4.1 //Switches to another branch
git branch -D master //Deletes the master branch
git branch -a //List all the remote branches
git checkout -b master remotes/trunk //Creates the branch master pointing to remotes/trunk
Get Information
git remove show origin //Gets the remote URL of repository connected to my local one. Actually the branches are connected.
Migrate a Subversion Repository
Just follow these instructions
Integration with other Tools
KDiff3 Merge Tool TODO A link in my wiki
Use a HTTP Proxy
git config --global http.proxy http://user1:12345@proxy-kibay:8080
Accept self-signed certificates
git config --global http.sslVerify false
Merge two repository keeping the log
git remote add geobi_acme https://dev.acmesws.de/git/geobi git fetch geobi_acme git checkout -b geobi_in_acme geobi_acme/master mkdir geobi_in_acme git mv * geobi_in_acme git commit -m "Merge repository GeoBI" git checkout master git merge geobi_in_acme #Local branch git commit git push
The deletion of the local and remote branches is optional:
git remote rm geobi_acme
git branch -d geobi_in_bbv