Difference between "git add -A" and "git add ."
2022-12-31
Question What is the difference between git add [--all | -A] and git add .? Answer This answer only applies to Git version 1.x. For Git version 2.x, see other answers. Summary: git add -A stages all changes git add . stages new files and modifications, without deletions (on the current directory and its subdirectories). git add -u stages modifications and deletions, without new files Detail: git add -A is equivalent to git add .…
Finding what branch a Git commit came from
2022-12-31
Question Is there a way to find out what branch a commit comes from given its SHA-1 hash value? Bonus points if you can tell me how to accomplish this using Ruby Grit. Answer While Dav is correct that the information isn't directly stored, that doesn't mean you can't ever find out. Here are a few things you can do. Find branches the commit is on git branch -a --contains <commit> This will tell you all branches which have the given commit in their history.…
Ignore files that have already been committed to a Git repository [duplicate]
2022-12-31
Question This question already has answers here: </div> How do I make Git forget about a file that was tracked, but is now in .gitignore? (33 answers) Closed 5 years ago. I have an already initialized Git repository that I added a .gitignore file to. How can I refresh the file index so the files I want ignored get ignored? Answer To untrack a single file that has already been added/initialized to your repository, i.…
What's the difference between HEAD^ and HEAD~ in Git?
2022-12-31
Question When I specify an ancestor commit object in Git, I'm confused between HEAD^ and HEAD~. Both have a "numbered" version like HEAD^3 and HEAD~2. They seem very similar or the same to me, but are there any differences between the tilde and the caret? Answer Rules of thumb Use ~ most of the time — to go back a number of generations, usually what you want Use ^ on merge commits — because they have two or more (immediate) parents Mnemonics:…
Why is Git not considered a "block chain"?
2022-12-31
Question Git's internal data structure is a tree of data objects, wherein each objects only points to its predecessor. Each data block is hashed. Modifying (bit error or attack) an intermediate block will be noticed when the saved hash and the actual hash deviate. How is this concept different from block chain? Git is not listed as an example of block chains, but at least in summaries, both data structure descriptions look alike: data block, single direction reverse linking, hashes, .…
How do I change the URI (URL) for a remote Git repository?
2022-12-30
Question I have a repo (origin) on a USB key that I cloned on my hard drive (local). I moved "origin" to a NAS and successfully tested cloning it from here. I would like to know if I can change the URI of "origin" in the settings of "local" so it will now pull from the NAS, and not from the USB key. For now, I can see two solutions:…
How to compare files from two different branches
2022-12-30
Question I have a script that works fine in one branch and is broken in another. I want to look at the two versions side-by-side and see what's different. Is there a way to do this? To be clear I'm not looking for a compare tool (I use Beyond Compare). I'm looking for a Git diff command that will allow me to compare the master version to my current branch version to see what has changed.…