This is easy enough
git rev-parse HEAD.
If you hate
git submodule, then you may want to give
git subtree a try.
Let's say you have a git repository
init'd with at least one commit.
You can add another repository to this respository like this:
In other words
- First specify you want to add the subtree
- Then specify the prefix directory into which you want to pull
- Specify the remote repository
- Specify the remote branch
- Specify you want to squash all the remote repository's logs
git subtree add --prefix .vimrepo https://github.com/newfivefour/vimrc.git master --squash
This will clone
https://github.com/newfivefour/vimrc.git into the directory
If you want to pull in any new commits to the subtree from the remote, issue the same command as above, replacing
git subtree pull --prefix .vimrepo https://github.com/newfivefour/vimrc.git master --squash
If you make a change to anything in
.vimrepo the commit will be stored in the host repository and its logs.
That is the biggest change from submodules.
If you now want to update the subtree repository with that commit, you must run the came command as above, excluding
--squash and replacing
git subtree push --prefix .vimrepo https://github.com/newfivefour/vimrc.git master
I've only just starting playing, but my main problems so far:
Other than that, they're looking nicer than submodules.
- You can't easily list the subtrees in your project
- You can't, at least easily, list the remote repositories of the subtrees
- The logs are slightly confusing when you update the host repository with subtree commits, then push the subtree to its host, and then pull the subtree.
If you run
git diff > your.patch
The normal git diff output will be saved to a file.
If you take that and apply it to the directory with patch, you'll update your files.
patch -p1 < your.patch
You need -p1 since in the diff output the file name are like
And you only need the 'your/directory/...' bit, so p1 says ignore everything up until after the first slash.
If you want to make backups, issue patch -p1 with the -b argument.
git git-diff unix unix-patch
If you want to checkout a file as it was one revision ago on the master branch:
git checkout master~1 thedir/thefile.txt
I used this to remove an update to a file when amending a commit.
(I hadn't pushed to master, hence the ability to amend without screwing things up.)
You may have a file which you want under source control, but you don't want its changes tracked. You can tell git - in this repository only - to ignore such changes.
I have a 'twitter secret keys' file that a build script modifies to insert the keys. I don't want those changes visible on the public repository.
You can tell git to ignore future changes via:
git update-index --assume-unchanged twitter_secrets_file.txt
Note that if you change branches or reset, it will moan if this has been changed anyway. You'll have to git checkout it to revert any changes.
Page 2 of 3