stackoverflow.com

I had some problems with Git and the file spec/fixtures/ČeskýÁČĎÉĚÍŇÓŘŠŤÚŮÝŽáčďéěíňóřšťúůýž. After pulling the latest commits, it would show that file as untracked, but adding and committing it would throw...

...in unicode fixture file once again' did not match any file(s) known to git. Solution Install Git version > 1.8.2 using homebrew and set git config --global core.precomposeunicode true

Say you want to move a git repository from one remote (perhaps Github) to another (perhaps Gitlab). If you have the repo checked out, you still should make sure to...

...current repo, and not the source repo, potentially missing commits. You can use this: git remote rename origin old-origin git remote add origin git fetch old-origin --prune

So you're using multiple remotes that offer the same branch? $ git branch -a | grep my-branch remotes/something/my-branch remotes/origin/my-branch And when trying to check out that remote branch, it fails...

...for you with an error like this? $ git checkout my-branch error: pathspec 'my-branch' did not match any file(s) known to git. Git usually guesses the remote branch...

To delete a local branch git branch -d the_local_branch To remove a remote branch (if you know what you are doing!) git push origin :the_remote_branch

...simply use the new syntax (v1.7.0) git push origin --delete the_remote_branch Note If you get the error error: unable to push to unqualified destination: the_remote_branch

When you want to do a git diff but do not care about the full diff and just want to know which files changed, use the --name-only switch:

...app/models/user.rb features/sign_in.feature To include some brief information about changed lines, use the --stat switch: $ git diff --stat app/controllers/sessions_controller.rb | 8 +- app/models/user.rb | 30 ++++ features/sign_in.feature | 136 +++++++++++++++++ The output of --stat is nicely colored...

makandra dev
stackoverflow.com

Assuming you're wanting to undo the effects of git rm or rm followed by git add -A or something similar: This restores the file status in the index:

then check out a copy from the index git checkout -- To undo git add , the first line above suffices, assuming you haven't committed yet. Note:

makandra dev

For every commit you need to revert, starting at the most recent, do: git revert -n [COMMIT] #revert, but don't automatically commit ... #fix any conflicts git reset #unstage...

git add -p #this will ask you for every change, whether you want to go through with the revert (i.e. "y" will revert, "n" will not; "?" for help...

pivotallabs.com

...we didn't lose any changes. Our solution is to clone the project's git repository into a folder inside a shared Dropbox folder...

When you have files in your .gitignore they won't be considered for changes, but still you might want to get rid of them, e.g. because they clutter your file...

While a regular git clean will ignore them as well, passing the -x switch changes that: git clean -x If you want to see what would happen first, make...

makandra dev

git apply allows you to apply a diff onto your HEAD. Most often you can achieve the same result with a rebase & merge. Example: master commit1 - commit3 feature-branch \ commit2...

git checkout feature-branch git reset --hard commit3 git diff ..commit4 | git apply master commit1 - commit3 feature-branch \ Unstaged commit 2 & 4 You can also create a patch and...

...path(s) to your file(s) which you would like to ignore to your .gitignore file (and commit them). These file entries will also apply to others checking out the...

...path(s) to your file(s) which you would like to ignore to your .git/info/exclude file. These file entries will only apply to your local working copy.

In order to clone a git repository including all branches and tags you need to use two parameters when cloning the old and pushing to the new repository respectively:

...clone --bare http://example.com/old-repo.git cd old-repo git push --mirror http://example.com/new-repo.git Of course, the URLs to your repository might look different depending on the protocol used, username...

When you do a git add . and have deleted files, git won’t stage them to be commited (as deleted). Use git add -u From the git documentation: -u, --update...

...and push it to origin, you won't be tracking it. This means a git pull won't know its remote version. You could use difficult commands to set up...

...is up to date or successfully pushed, add upstream (tracking) reference, used by argument-less git-pull(1) and other commands. For more information, see branch..merge in git-config...

To change the commit message of the latest (unpushed, unmerged) commit, you can use git commit --amend To change the commit message of an earlier (unpushed, unmerged) commit [COMMIT], you...

git rebase -i COMMIT~ For a current version of git, you can simply mark the line with "reword", and git will ask you later for the new message...

makandra dev

If you modified git's history and the change was already pushed, you will usually get a ! [rejected] my-branch -> my-branch (non-fast-forward) error, when trying to push...

...You can force the push, with git push --force origin my-branch Careful: You might lose history. Unless your git is configured to push only the current branch, you must...

Merging .po-files with Git is painful. There have been attempts of making Git more clever when trying to merge .po-files. I believe however that this is not enough...

...invalid merges I additionally disable merging for po files altogether, by adding the following .gitattributes file to the root of the repository: *.po merge=binary *.pot merge=binary

richfrog.curzons.net

...up a cmd and put the full path to PuTTY's plink.exe into the GIT_SSH environment variable, e.g.: set GIT_SSH=D:\PuTTY\plink.exe You can then use Git...

...like you would on any sane operating system. Just go ahead and git clone, git pull, etc. Also, you may want to add the environment variable under the Windows system...

...change a commit message of the most recent (unpushed) commit, you can simply use git commit --amend -m 'new message' To change messages of (unpushed) commits further in the past...

...git rebase -i [COMMIT BEFORE THE FIRST YOU WANT TO EDIT] Mark all messages to be changed with "edit". Git will start the rebasing and stop at every marked commit...

...still have your locally cached versions of those branches (which is actually good) but git branch -a will still list them as remote branches. You can clean up that information...

...locally like this: git remote prune origin Your local copies of deleted branches are not removed by this. The same effect is achieved by using (kudos to Julien):

makandra dev

Every time you amend, rebase or reset, git commits get "overwritten". However, git still allows you to checkout those commits using their SHA1, given you can find it.

git reflog # or git reflog show [BRANCH] This will show a list of all commits the branch has recently pointed to. Git might garbage collect those...

Instead of showing you two lines for each change, Git allows you to highlight changes in a line explicitly: git diff --word-diff some_file Hello [-world-]{+universe+}!

...unhandy to use.\ You maybe just want the diff put into your terminal: PAGER='' git diff --word-diff some_file

kernel.org

The ‘merge.*.driver` variable’s value is used to construct a command to run to merge ancestor’s version, current...

makandra dev

Git has a built-in repository viewer for your web browser. a bit similar (but less awesome) than github. If you have apache installed, simply go to your repository, and...

git instaweb --httpd apache2 otherwise, simply install lighttpd and just run git instaweb This should open a brower automatically pointing to your repository. If not, try to connect to...