How do I diff the same file between two different commits on the same branch?
2022-07-20
Question In Git, how could I compare the same file between two different commits (not contiguous) on the same branch (master for example)? I'm searching for a compare feature like the one in Visual SourceSafe (VSS) or Team Foundation Server (TFS). Is it possible in Git? Answer From the git-diff manpage: git diff [--options] <commit> <commit> [--] [<path>...] For instance, to see the difference for a file "main.c" between now and two commits back, here are three equivalent commands:…
How can I merge multiple commits onto another branch as a single squashed commit?
2022-07-19
Question I have a remote Git server, here is the scenario which I want to perform: For each bug/feature I create a different Git branch I keep on committing my code in that Git branch with un-official Git messages In top repository we have to do one commit for one bug with official Git message So how can I merge my branch to remote branch so that they get just one commit for all my check-ins (I even want to provide commit message for this)?…
No submodule mapping found in .gitmodule for a path that's not a submodule
2022-07-19
Question I have a project that has a submodule at lib/three20 My .gitmodule file looks like this: [submodule "lib/three20"] path = lib/three20 url = git://github.com/facebook/three20.git I have cloned this in the past without errors, (git submodule init followed by a git submodule update) and it's been working for a while. I tried to clone this to a new machine, and now I'm getting this error on git submodule init: No submodule mapping found in .…
What to do with commit made in a detached head
2022-07-19
Question Using git I made something like this git clone git checkout {a rev number tree rev before} (here I started to be in a detached head state) //hacking git commit //hacking git commit (some commit where made on origin/master) git pull (which does complete because there was some error due to the fact that I'm no more on master) Because it said to me that I can still commit when in a detached head state, I did so.…
How do I fix a Git detached head?
2022-07-18
Question I was doing some work in my repository and noticed a file had local changes. I didn't want them anymore so I deleted the file, thinking I can just checkout a fresh copy. I wanted to do the Git equivalent of svn up . Using git pull didn't seem to work. Some random searching led me to a site where someone recommended doing git checkout HEAD^ src/ (src is the directory containing the deleted file).…
git add, commit and push commands in one?
2022-07-16
Question Is there any way to use these three commands in one? git add . git commit -a -m "commit" (do not need commit message either) git push Sometimes I'm changing only one letter, CSS padding or something. Still, I have to write all three commands to push the changes. There are many projects where I'm only one pusher, so this command would be awesome! Answer Building off of @Gavin's answer:…
How to use Visual Studio Code as default editor for git?
2022-07-15
Question When using git at the command line, I am wondering if it is possible to use Visual Studio Code as the default editor, i.e. when creating commit comments and looking at a diff of a file from the command line. I understand that it won't be possible to use it for doing merges (at least at the minute) but does anyone know if it is possible to use it for looking at diff's, and if so, what command line options would be required in the .…