Git --amend in Eclipse JAVA - java

I tried to Push some files in git
For example a,b,c,x,y,z files..
I did commit ammends after i found some mistakes int he files...
I did commit amend for same files and pushed same files a,b,c,x,y,z
After Some commits I realized that , i dont want file "C" instead I want file "D".
I added file "D" and did commit amend..
Now everything goes fine but now I could see all files after commit amend
a,b,c,d,x,y,z
but I dont want to send C file to git
I want remove file C after doing commmit amend and
want to see only
a,b,d,x,y,z files
I am using Eclipse,JAVA for doing this process
Any help appreciated

Git's --amend option only allows you to amend the last commit. If you want to amend commits you have done sometimes ago. You need to follow this:
How to modify a specified commit in git?

Related

Git: Comparing two files in two branches [duplicate]

Is it possible to open a file in a git branch without checking out that branch? How?
Essentially I want to be able to open a file in my github pages branch without switching branches all the time. I don't want to modify it, just want to view it.
This should work:
git show branch:file
Where branch can be any ref (branch, tag, HEAD, ...) and file is the full path of the file. To export it you could use
git show branch:file > exported_file
You should also look at VonC's answers to some related questions:
How to retrieve a single file from specific revision in Git?
How to get just one file from another branch
UPDATE 2015-01-19:
Nowadays you can use relative paths with git show a1b35:./file.txt.
git show somebranch:path/to/your/file
you can also do multiple files and have them concatenated:
git show branchA~10:fileA branchB^^:fileB
You do not have to provide the full path to the file, relative paths are acceptable e.g.:
git show branchA~10:../src/hello.c
If you want to get the file in the local directory (revert just one file) you can checkout:
git checkout somebranch^^^ -- path/to/file
A simple, newbie friendly way for looking into a file:
git gui browser <branch> which lets you explore the contents of any file.
It's also there in the File menu of git gui. Most other -more advanced- GUI wrappers (Qgit, Egit, etc..) offer browsing/opening files as well.
If you're using Emacs, you can type C-x v ~ or M-x vc-revision-other-window to see a different revision of the file you're currently editing (tags, branches and hashes all work).
Add the following to your ~/.gitconfig file
[alias]
cat = "!git show \"$1:$2\" #"
And then try this
git cat BRANCHNAME FILEPATH
Personally I prefer separate parameters without a colon. Why? This choice mirrors the parameters of the checkout command, which I tend to use rather frequently and I find it thus much easier to remember than the bizarro colon-separated parameter of the show command.

Sticky tag for file is not a branch - CVS

I'm trying to commit my changes to the repository server (using CVS) in Eclipse Kepler, but when I do I get the following error which I've never seen before:
The server reported an error while performing the "cvs commit"
command. ProsperityMobile: cvsntsrv server: sticky tag 1.6' for file
src/com/prosperity/mobile/controller/UserController.java' is not a
branch ProsperityMobile: cvsntsrv server: sticky tag 1.14' for file
src/com/prosperity/mobile/service/UserService.java' is not a branch
ProsperityMobile: cvsntsrv [server aborted]: correct above errors
first!
And honestly I don't even know where to start trouble shooting this or what it even means. Any point in the right direction would really be appreciated!
I just came upon this too. This may happen, when you checkout a specific version of a file or at some specific date, see Sticky tags for more.
In my case, the files had a sticky tag, but were also at the HEAD. So I could just remove the sticky tag with
cvs update -A file.h file.cpp
and then proceed with cvs commit
And again when you're on a branch, it works more or less the same. Just update to the relevant branch with option -r
cvs update -r <branch-name> file.h file.cpp
In order to remove sticky tag from a file in CVS, easily use:
cvs update -A filename
A Tag applies to a specific revision of a file or tree of files. Trying to Commit changes to that wouldn't make sense, and in fact isn't supported by the server. This is why you check things out from a Branch, make changes and then check them back into the branch. A branch is expected to change over time while tags are expected to always point you back to the specific revision.
http://commons.oreilly.com/wiki/index.php/Essential_CVS/Using_CVS/Tagging_and_Branching
I had this same problem in Eclipse, and updating would not work.
What worked was:
Right click on file
Replace with > Another Branch or Version
Confirm (this will override local changes, therefore you should backup them)
Select HEAD (or the branch you need)

How to delete a file locked by the Java Platform?

I am currently developing an app which clones Git repositories thanks to JGit (http://wiki.eclipse.org/JGit/User_Guide) every time a user logs on. When the user wants to quit the app, I want to delete the clone.
Here's the problem : when cloning a repository, a folder .git is created, in which can be found a file .pack (.git/objects/pack/sutpideFile.pack) and which cannot be deleted, because the Java Platform is locking it (when trying to delete it by hand, get the error 'The action can't be completed because file is open in Java(TM) Platform SE binary').
THIS IS A KNOWN PROBLEM with Jgit : .pack file from git repo can't be deleted using File delete() method.
Thus I have used the solution proposed here : https://github.com/ajoberstar/grgit/issues/33 which is to add those three lines before my deleting method :
WindowCacheConfig config = new WindowCacheConfig();
config.setPackedGitMMAP(true);
WindowCache.install(config);
BUT what really bothers me because I do not understand is that this solution works only once: I launch the server (TomCat), connect, and then disconnect. Here, the whole folder is deleted. However, when I re-connect and disconnect (without re-launching the sever), there rebels the files and am I not able anymore to delete it until I shut down the server.
Has anybody the slighest idea why it works, but only once ?
Thanks for your help,
EDIT :
Well, so I just needed to add git.getRepository().close(); when I finish to use the Git object. Then the deletion is possible !
This is a know bug in JGit, see the discussion at How do I release file system locks after cloning repo via JGit
Basically you currently need to add the call to "Git.getRepository().close()" in order to free all file system locks until a new version of JGit is released.
result = Git.cloneRepository()
.setURI( 'https://github.com/github/testrepo.git' )
.setDirectory( localPath )
.call();
// this is currently necessary to free all file locks
result.getRepository().close();
result.close();
JGit 4.1 is scheduled to have a fix for this included.

Is it possible to ignore a file once it is already tracked in Git?

Is it possible to add a dummy configuration file once (so that other developers can see how the configuration file should look) and then ignore it using the .gitignore file. Then replace the dummy config details with working ones so I can continue to develop the project and keep committing changes? But the original dummy config file will remain intact on Github?
This is the approach I attempted:
create repository on Github
intitialise local repo
pull remote repo
push local repo to github with Configuration.java (containing dummy details)
add Configuration.java to the .gitignore file
push local repo to github
add correct details to Configuration.java
push local repo to github
But the change to configuration.java is tracked, so this doesn't work.
If you are just worried about ignoring changes in your local dev repo, you can use git update-index --assume-unchanged <file> to ignore any changes to the file. See http://blog.pagebakers.nl/2009/01/29/git-ignoring-changes-in-tracked-files/ for more details.
You mention :
push local repo to github with Configuration.java (containing dummy
details)
add Configuration.java to the .gitignore file
The problem with this is, gitignore only works on files that aren't already being tracked, and since you've committed it it's too late for the gitignore to work. To quote the gitignore docs:
A gitignore file specifies intentionally untracked files that Git
should ignore. Files already tracked by Git are not affected;
If you want to commit your own work to a publicly visible repo, but want to hide sensitive info such as connection strings / passwords etc, then commit a dummy file first. For example, commit something like this:
public class Configuration {
public static final String USERNAME = "someUsername";
public static final String PASSWORD = "passwordHere";
}
Then, tell git to stop tracking changes on that file, so you can amend the values locally but not be prompted to commit those changes.
git update-index --assume-unchanged path/to/file.txt
A couple of things to point out:
Always check in a dummy config file, don't leave it out entirely. If
you do, when people checkout your project and the file is missing,
they won't be able to compile the project! Help them by giving some
sample data.
As git is no longer tracking that file, if you make any modifications
that you DO want to commit, you'll have to manually cater to that
(either do it via github.com or turn tracking back on, fix it, then
disable tracking again). For this purpose, keep that file relatively light, just variables, don't put logic in there that you may need to keep updating.

JGIT: git checkout --

I have a not staged modified file and I would like to discard the changes.
In git it would be something like
git checkout -- .
How can I emulate this behavior with JGit ?
Thanks in advance.
To revert a single file, you could use the CleanCommand:
Set<String> paths = new HashSet<String>();
paths.add( ... );
git.clean().setPaths( paths ).call();
Unfortunately there is a bug that prevents the CleanCommand to reset files in sub-directories.
If I interpret the '.' in git checkout -- . correctly you want to revert all changes in the work directory. The ResetCommand does that:
git.reset().setMode( ResetType.HARD ).call();
This would also override the index with the contents from HEAD.
If you don't care about the index, you could also read the file-contents from the HEAD commit and write them to the work directory yourself. Let me know if that is of interest for you and I will try to assemble a snippet that does so.

Categories

Resources