Table of Contents
See diff between local commits and remote master
git diff master origin/master
Pull from origin and overwrite local changes
git reset --hard; git pull -Xtheirs
Useful if you have local changes that you do no longer need.
Mark file as 'unchanged'
This will ignore the file on all commits using the -a argument.
git update-index --assume-unchanged [file]
To include the file in commites again use:
git update-index --no-assume-unchanged [file]
This is particularly handy when making local changes to a config file that must not enter the central repository.
List current status (including changes) in repo
List files in repo
List deleted files in repo
git ls-files -d
git checkout filename
Undelete all deleted files
git ls-files -d | xargs git checkout --
Mark conflict as resolved
filename will have merge conflicts marked in the same way used in CVS.
git add filename
marks the conflict as resolved.
Turn off pager
git --no-pager [command]
alias git='git --no-pager'
to disable it on all commands in the current shell.
core.pager = in .gitconfig (it is set to the empty string.) to disable it entirely for that user.
# create tag locally: git tag -a v1.4 -m 'version 1.4' # push tag to server: git push –-tags
git tag -l v1.*
git show v1.4
# delete tag locally: git tag -d v1.0 # push tag deletion to origin: git push origin :refs/tags/v1.0
Create and switch to:
git checkout -b [branchname]
git branch [branchname]
Push to server:
git push -u origin [branchname]
Switch to branch
git checkout [branchname]
git branch -d branchname git push origin --delete branchname
Fecth branches from server
git fetch --all
CVS 2 GIT
git cvsimport -k -i -d server:/path/to/CVSHOME -C git_reponame cvs_reponame
The resulting git_reponame directory now contains the .git folder which can be moved to a server location for shared access.
git update-server-info in the new server folder in order to make it shareable.
Creating a new repository
As root: mkdir /home/git/repos/[reponame].git cd /home/git/repos/[reponame].git git --bare init git update-server-info chown -R apache:apache /home/git/repos/[repomame].git
Now clone the project on a client, add some files and commit them. When pushing them for the first time use the following command:
git push origin master
NOTE: If this is done by the usual 'git push' command, a 'No refs in common and none specified; doing nothing.' error will be issued.
Set up repository mirror
# Create a bare clone of the repository. git clone --bare https://github.com/exampleuser/old-repository.git # Mirror-push to the new repository. cd old-repository.git git push --mirror https://github.com/exampleuser/new-repository.git
Move single directory to its own repository
Replace email address in commits and tags
NOTE: The way the push command is performed is important in order to overwrite bot commits and tags.